This is probably standard SQL but I can't figure it out. I have a simple arrangement in SQLAlchemy.
There are 4 tables: item_table --> mapped to Item section_table --> "" Section keyword_table --> "" Keyword itemkeyword_table There is a many-to-many relationship between item and keyword contained in itemkeyword_table. The is a one-to-many relationship between section_table and item_table that uses a section_id foreign key in item_table. I have the mappers you'd expect. My problem is that I am trying to construct a query that produces all the keywords that are relevant to a particular section. I was hoping that something like: session.query(Keyword).select(...) but I cannot produce a select that works. Using a mix of SQLAlchemy and python code, the following works: (a_section is an SQLAlchemy Section object for one of the sections) a_sections_keywords = [] for item in a_section.items: ....for keyword in item.keywords: ........if keyword not in a_sections_keywords: ............a_sections_keywords.append(keyword) However, it seems to me that there is probably a database query that produces the same result -- I just can't figure out what it is. Thanks for any help. Steve ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users