Having trouble getting this syntax right:
SELECT DISTINCT id
FROM metadata
WHERE (meta_key = 'school' AND meta_value = 'Some School')
AND WHERE (meta_key = 'hidden' AND meta_value = '1')
Its failing at line 4…
UPDATED:
Table looks like this:
meta_id - id - meta_key - meta_value
1 1 school Some School 1
2 1 hidden 0
3 2 school Some School 2
4 2 hidden 1
5 3 school Some School 3
6 3 hidden 0
7 4 school Some School 4
8 4 hidden 0
9 5 school Some School 5
10 5 hidden 1
UPDATED: I have a related, extended here Does row exist and multiple where
You do not need a second
where, and the secondandwas probably intended to be anor:(the reason I think you wanted an
oris because otherwise you have a conjunction of contradictory clausesmeta_key = 'school' AND meta_key = 'hidden', which is always false).EDIT : In response to OP’s comment about the results he is trying to get, here is a different query:
Now the conjunction clauses are no longer contradictory, because they refer to two different rows
m1andm2.