I have a table that's holding metadata for entrys from another table. The metadata-table looks like this (I removed relating Ids so it's more obvious):
id entry_id property value
1 12 color blue
2 12 shape circle
3 13 color red
4 13 shape circle
5 14 color blue
6 14 shape square
7 15 material stone
8 12 material plastic
Now I want to search this table for the properties, like choosing all entries where color is blue:
select entry_id from table where property = 'color' and value = 'blue'
So far, so good. But how do I expand the query when I have multiple conditions? For example I want to search for all entries where color is blue and shape is circle. Right now I'd achieve this with unions:
select entry_id from table where property = 'color' and value = 'blue'
union
select entry_id from table where property = 'shape' and value = 'circle'
this obviously gets ugly the more properties I want to look for. And I think it's not very fast, too. Is there are more elegant way to do this? The reason for this table is, that I have objects with metadata which can be set by the user.
Thank you!