简体   繁体   English

如何仅选择相关帖子的隐私为0的那些评论

[英]How to select only those comments where associated posts's privacy is 0

I have a table "Posts" that looks like this- 我有一个表格“帖子”,看起来像这样-

------------------------------------
id  |  Title | Date | Privacy 
1   | abc    | 2016 | 0
2   | xyz    | 2015 | 1

And another table "comments" that looks like this- 另一个表“ comments”如下所示:

------------------------------------
id  | post_id | content | Date   
1   |  2       |  abc    | 2016 
2   |  1       |  xyz    | 2015 

I need to select all the comments - 我需要选择所有评论-

a) whose post's privacy is 0 a)帖子的隐私为0
b) Where comments.content is like '%keyword%' b)其中comments.content类似于'%keyword%'
c) order by comments.date c)按评论顺序排列
d) Limit and offset values d)极限值和偏移量

Your help will be much appreciated. 您的帮助将不胜感激。 Thanks! 谢谢!

Do you mean: 你的意思是:

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

Please explain what you mean with: " d) Limit and offset values " 请解释一下您的意思:“ d)极限和偏移值

You should first search for an answer already given on stack overflow or just make a google search. 您应该首先搜索堆栈溢出时已经给出的答案,或者只是进行Google搜索。

Anyway here is your answer 反正这就是你的答案

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM