行是否存在且存在多个where
我刚刚问了这个问题多个Where条件,但意识到还有更多内容(并且没有想要混淆另一个问题)。
我有一个看起来像这样的表格:
meta_id - id - meta_key - meta_value
1 1 school Some School 1
2 2 school Some School 2
3 2 hidden 1
4 3 school Some School 3
5 4 school Some School 4
6 5 school Some School 5
7 5 hidden 1
由于我之前的问题,我有这样的语法:
SELECT DISTINCT m1.id
FROM metadata m1
join metadata m2 on m1.id = m2.id
WHERE (m1.meta_key = 'school' AND m1.meta_value = 'Some School 1')
AND (m2.meta_key = 'hidden' AND m2.meta_value = '1')
如果 school = Some School 1
和 hidden = 1
则找到 id
但是问题是,hidden
行仅在隐藏时才存在,如果不隐藏则不存在 - 所以它不像 hidden = 0
意味着它不存在那么简单隐藏和 hidden = 1
表示它是隐藏的。
因此,我需要找出 school = Some School 1
并且对于相同的 id
,行 hidden
不存在。
I just asked this question Multiple Where conditions, but realised there was more to it (and didn't want to confuse the other question).
I have a table that looks like this:
meta_id - id - meta_key - meta_value
1 1 school Some School 1
2 2 school Some School 2
3 2 hidden 1
4 3 school Some School 3
5 4 school Some School 4
6 5 school Some School 5
7 5 hidden 1
Thanks to my previous question I have this syntax:
SELECT DISTINCT m1.id
FROM metadata m1
join metadata m2 on m1.id = m2.id
WHERE (m1.meta_key = 'school' AND m1.meta_value = 'Some School 1')
AND (m2.meta_key = 'hidden' AND m2.meta_value = '1')
which finds the id if the school = Some School 1
and hidden = 1
But the problem is that the row hidden
is only there if it is hidden, it doesn't exist if its not hidden - so its not as easy as hidden = 0
means its not hidden and hidden = 1
means its hidden.
So I need to find out school = Some School 1
and that for the same the id
, the row hidden
doesn't exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)