I have two tables Items and ItemDescriptions
class Item(Base):
__tablename__ = "item"
id = Column(Integer, primary_key=True)
description_id = Column(Integer, ForeignKey('item_description.id'))
class ItemDescription(Base):
__tablename__ = "item_description"
id = Column(Integer, primary_key=True)
Given a list of ItemDescriptions I want a list of Items such that there is one item of each ItemDescription id. I don’t care which item.
[Edited for clarity]
Given this list of item and descriptions:
Item, Description
1 , 1
2 , 1
3 , 1
4 , 2
5 , 2
6 , 3
7 , 3
8 , 3
I want a query that will return something like:
Item, Description
2 , 1
4 , 2
7 , 3
I’m having trouble working out the sub-queries etc.
Thank you for your help
I am a big fan of column_property. Here’s a way to do what you want with column_property: