【发布时间】:2018-11-23 07:06:53
【问题描述】:
我想合并两张表。 表 A:具有多个具有唯一 URL 的帖子,表 B 对表 A 中的特定帖子进行投票。 现在我想列出表 A 中的所有行,如果帖子在表 B 中有投票,则将其附加到一行。 我试过这个,但它排除了将表 A 与表 B 匹配的帖子。它只返回没有任何投票。
SELECT a.id,a.url,a.content,a.sourcetype,a.width,a.height,a.totalvotes,a.score, b.postid,b.userid,b.votetype
FROM create_general a
LEFT JOIN votes b ON a.url=b.postid
WHERE a.status='1' and a.score > 0 order by a.url desc
LIMIT 24
【问题讨论】:
-
看起来您需要使用 post id LEFT JOIN votes b ON a.id=b.postid 加入两个表