Michael,
Thanks for your help once again. Unfortunately I'm just not 'getting it'; I can't make the query work the way you describe. So I'm bailing out and going back to plan SQL statements till I have more time to work on this. Again, thanks for your help and guidance, I'm determined to make better use of SqlAlchemy, but I have to move ahead on the project I'm on right now. Doug From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bayer Sent: Friday, September 26, 2008 11:03 AM To: [email protected] Subject: [sqlalchemy] Re: How to perform inner joins On Sep 26, 2008, at 9:23 AM, Doug Farrell wrote: I'm trying to represent a many-to-many relationship between the press_table and the press_routing table using the linking table, press_routing_press. I think I've got the table structure and mapping set up, but now I need some help to build a query using SqlAlchemy that does the same thing as this MySQL query: select p.id, p.code from press p inner join press_routing_press prp on p.id=prp.press_id inner join press_routing pr on pr.id=prp._press_routing_id where pr.code='A' Hi Doug - this kind of join is described at http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_joins , the fourth example (albeit its for a one-to-many, the approach is the same with a "secondary" table). The approach here is: sess.query(Press).join(Press.routes).filter(PressRouting.code=='A').all( ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
