On PostgreSQL, I have a table item, and a table item_attribute. So an item can have multiple attributes.
table: item
id | name |
---|---|
1 | A |
2 | B |
3 | C |
table: item_attribute
id | item_id | name | value |
---|---|---|---|
1 | 1 | foo | bar |
2 | 1 | size | M |
3 | 1 | country | DE |
4 | 2 | foo | baz |
5 | 2 | size | M |
6 | 2 | country | DE |
7 | 3 | other | test |
8 | 3 | size | M |
9 | 3 | country | EN |
Now, I need to find items that match a given set of attribute name/value pairs
So, let's say I want to find items with attributes of country
with value DE
and size
with value M
the result set should be
id | name |
---|---|
1 | A |
2 | B |
if I want to find items with attributes of country
with value EN
and size
with value M
the result set should be
id | name |
---|---|
3 | C |
Any hints here?