I have a table of custom data (called fields)
lets just say:
table users
id, email
1, a@b.c
2, d@e.f
table fields
field_id, userid, value
1,1,'aaa'
2,1,'bbb'
1,2,'aaa'
2,2,'ccc'
I am having problems with the WHERE part of my clause.. I want to select all rows where the user has field_id[1] a value of 'aaa' and also has a field_value[2] of 'bbb'...
WHERE (f.field_id=1 AND f.field_value = 'aaa') AND (f.field_id=2 AND f.field_value = 'bbb')
hope someone can help me make it work, thanks!!
The full query:
SELECT u.* FROM users AS u, fields AS f WHERE (f.field_id=1 AND f.field_value = 'aaa') AND (f.field_id=2 AND f.field_value = 'bbb')
so I would only want to get user 1 because they match both 'aaa' and 'bbb', but user 2 does not...
thankss!
|