多个Where条件
无法正确使用此语法:
SELECT DISTINCT id
FROM metadata
WHERE (meta_key = 'school' AND meta_value = 'Some School')
AND WHERE (meta_key = 'hidden' AND meta_value = '1')
它在第 4 行失败...
更新: 表格如下所示:
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
更新:我在这里有一个相关的扩展行是否存在且存在多个where
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要第二个
where
,第二个and
可能旨在成为or
:(我认为您想要一个 < code>or 是因为否则你会得到一个矛盾子句的连词
meta_key = 'school' AND meta_key = 'hidden'
,这总是错误的)。编辑:为了回应OP关于他试图获得的结果的评论,这里有一个不同的查询:
现在连词子句不再矛盾,因为它们引用了两个不同的行
m1< /code> 和
m2
。You do not need a second
where
, and the secondand
was probably intended to be anor
:(the reason I think you wanted an
or
is 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
m1
andm2
.不能有多个 WHERE 子句。我想你的意思是
You can't have multiple WHERE clauses. I think what you mean is