左右联接之间是否有区别,以下sql语句的结果相同,但是两者的性能相同吗?
SELECT count(*)
FROM writers
RIGHT JOIN blogs ON blogs.members_id = model_id
WHERE member_id = 123 AND blogs.status = 1;
SELECT count(*)
FROM blogs
LEFT JOIN writers ON writers.model_id = blogs.members_id
WHERE writers.member_id = 123
AND blogs.status = 1;
答案 0 :(得分:3)
完全没有区别。两者都实现了内部联接。 ??您以为您指定了outer join
,但是您的where
子句正在撤消它。
大概是您打算的:
SELECT count(*)
FROM blogs b LEFT JOIN
writers w
ON w.model_id = b.members_id AND w.member_id = 123
WHERE b.status = 1;
尽管您可以将其写为RIGHT JOIN
,但我强烈建议不要这样做。原因如下: