[英]How to select only those comments where associated posts's privacy is 0
我有一个表格“帖子”,看起来像这样-
------------------------------------
id | Title | Date | Privacy
1 | abc | 2016 | 0
2 | xyz | 2015 | 1
另一个表“ comments”如下所示:
------------------------------------
id | post_id | content | Date
1 | 2 | abc | 2016
2 | 1 | xyz | 2015
我需要选择所有评论-
a)帖子的隐私为0
b)其中comments.content类似于'%keyword%'
c)按评论顺序排列
d)极限值和偏移量
您的帮助将不胜感激。 谢谢!
你的意思是:
SELECT content
FROM comments C
INNER JOIN Posts P ON P.id = C.post_id
WHERE content like '%keyword%'
AND Privacy = 0
ORDER BY C.Date
请解释一下您的意思:“ d)极限和偏移值 ”
您应该首先搜索堆栈溢出时已经给出的答案,或者只是进行Google搜索。
反正这就是你的答案
select * from comments where
content like '%keyword%' and
post_id in ( select id from Posts where Privacy = 0)
order by Date
LIMIT 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.