【发布时间】:2016-03-25 11:13:38
【问题描述】:
SELECT *
FROM notifications
INNER JOIN COMMENT
ON COMMENT.id = notifications.source_id
WHERE idblog IN (SELECT blogs_id
FROM blogs
WHERE STATUS = "active")
INNER JOIN reportmsg
ON reportmsg.msgid = notifications.source_id
WHERE uid =: uid
ORDER BY notificationid DESC
LIMIT 20;
我在这里 INNER JOINing notifications 和 comment 和 reportmsg;然后用WHERE过滤内容。
但我的问题是,对于第一个INNER JOIN [即与comment],在加入notifications 与comment 之前,我想将notifications.idblog 与blogs.blogs_id 匹配和 em> SELECT 只有blogs.status = "active" 所在的那些行。
为了更好地理解上面的代码:
这里,对于INNER JOIN,对于comment,我只想SELECT notifications 中那些idblog 匹配blogs.blogs_id 的行并且 有status = "active"。 p>
第二个INNER JOIN 和reportmsg 不需要更改。也就是说,它只过滤uid。
【问题讨论】:
-
用于与关系数据库交互的语言称为 SQL,而不是 PHP。我已相应地编辑了您的问题。
-
由于
COMMENT是关键字,我会小心并在其周围加上反引号。 -
@bɪˈɡɪnə 检查我的答案是否满足......并告诉我在我的答案中错过了什么......
标签: mysql sql inner-join