db.define_table('user',SQLField('name'))
db.define)table('tag',SQLField('name'),SQLField('user_id',db.user))

user_id=db.user.insert(name='Jason')
db.tag.insert(name='web2py',user_id=user_id)
db.tag.insert(name='python',user_id=user_id)
db.user.insert(name='Massimo')

# inner join
for row in db(db.tag.user_id==db.user.id).select():
    print row.user.name, row.tag.name
# output
Jason web2py
Jason python

Notice Massimo is not listed because has no tags

# outer join
for row in db().select(db.tag.ALL, db.user.ALL,left=db.tag.on
(db.tag.user_id==db.user.id)):
    print row.user.name, row.tag.name
# output
Jason web2py
Jason python
Massimo None

# same as before but Massimo is listed even if no tags.

Massimo



On Jun 22, 12:33 pm, Jason Brower <[email protected]> wrote:
> I have 3 tables:
> 1 for tags
> 1 for users
> and one to stick them together based on there ID's
> How do I view all tags that a user has?
> I have the book, but I just don't know where to look.  Don't really know
> the difference between an inner outer left join. :/
> Regards,
> Jason Brower
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to