Hello, I have some troubles building a query. I have a table profiles with the fields (id, property, value) and the rows are like this => jim,language,de jim,gender,male jim,email,emailaddress@.... Now i want to filter on the property and my query is like this => SELECT * FROM profile WHERE property='language' AND value='de' AND property='gender' AND value='male' But it's not working its showing the wrong language. Can anyone help me ? Cheers, Kris
select * from profile where (property='language' OR property='gender') AND (value='de' OR value='male') when you use the operator AND it means both data/value must both true..
I think you would need to change the query a little bit, or else you could in theory get a row where property='language' and value='male'... select * from profile where (property='language' AND value='de') OR (property='gender' AND value='male')
You need something like this: select * from profile where (property='language' AND value='de') AND (property='gender' AND value='male') /* for each property */
It should be select * from profile where (property='language' AND value='de') OR (property='gender' AND value='male')
You require to use a self-join since the values are in different records: select a.id from profile a, profile b where (a.id = b.id and a.property='language' AND a.value='de' and b.property='gender' AND b.value='male')