我有一张桌子"帖子"看起来像这样 -
------------------------------------
id | Title | Date | Privacy
1 | abc | 2016 | 0
2 | xyz | 2015 | 1
另一张表"评论"看起来像这样 -
------------------------------------
id | post_id | content | Date
1 | 2 | abc | 2016
2 | 1 | xyz | 2015
我需要选择所有评论 -
a)其帖子的隐私是0
b)其中comments.content类似于'%keyword%'
c)通过评论订购
d)限值和偏移值
非常感谢您的帮助。谢谢!
答案 0 :(得分:0)
你的意思是:
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)限制和偏移值”
答案 1 :(得分:0)
首先应该搜索已经在堆栈溢出时给出的答案,或者只是进行谷歌搜索。
无论如何,这是你的答案
select * from comments where
content like '%keyword%' and
post_id in ( select id from Posts where Privacy = 0)
order by Date
LIMIT 10