Denes,

Where and how do I display db._lastsql?

The example comes from: http://mdp.cti.depaul.edu/examples/default/dal
the example about Left Outer Joins

I guess the idea of the example in SQL reads like:

SELECT person.name, dog.name
FROM person
  LEFT OUTER JOIN friendship ON person.id==friendship.person
  LEFT OUTER JOIN dog ON dog.id==friendship.dog
WHERE person.id>0

In the example:
query=(db.person.id>0)

and:
friends=(db.person.id==db.friendship.person)&
(db.dog.id==db.friendship.dog)

to me this is the JOIN condition of an INNER JOIN, so I have no idea
why Massimo repeats it in the OUTER JOIN example. Next in the example
is this line:

rows=db(query).select(db.person.name,db.dog.name,left=db.dog.on
(friends))

here I don't understand the left=db.dog.on(friends) part. You use a
LEFT OUTER JOIN to not loose the persons that don't have dogs in the
result. In the view this is indicated by 'nobody'. However, in the
friends condition you already loose the persons without a dog, then,
when you LEFT OUTER JOIN dog on friends that doesn't make sense.

{{extend 'layout.html'}}
{{for row in rows:}}
{{=row.person.name}}
is friend of
{{=row.dog.name or nobody}}
<br />

Is there a flaw in my reasoning?


> What you want is probably;
> rows=db(db.person.id>0).select(db.person.name,db.dog.name,left=
> [db.friendship.
> on(db.friendship.person==db.person.id),db.dog.on
> (db.friendship.dog==db.dog.id)])

Yes, to make sure I understand this ...

left=[db.friendship.on(db.friendship.person==db.person.id),db.dog.on
(db.friendship.dog==db.dog.id)])

in SQL would read like:

FROM friendship
  LEFT OUTER JOIN person ON friendship.person==person.id
  LEFT OUTER JOIN dog ON friendship.dog==dog.id


If I am right here I am reassured.


Kind regards,

Annet.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to