MySQL mysql中的左连接和右连接有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4407168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between left joins and right joins in mysql
提问by satyam
Possible Duplicate:
What is the difference between Left, Right, Outer and Inner Joins?
可能的重复:
左联接、右联接、外联接和内联接之间有什么区别?
What is the difference between left joins and right joins in mysql
mysql中的左连接和右连接有什么区别
回答by Chandresh M
The difference is in the way tables are joined if there are no common records.
如果没有公共记录,区别在于表的连接方式。
JOIN is same as INNER JOIN and means to only show records common to both tables. Whether the records are common is determined by the fields in join clause. For example:
JOIN 与 INNER JOIN 相同,表示只显示两个表共有的记录。记录是否通用由join子句中的字段决定。例如:
FROM t1
JOIN t2 on t1.ID = t2.ID
means show only records where the same ID value exists in both tables.
表示仅显示两个表中存在相同 ID 值的记录。
LEFT JOIN is same as LEFT OUTER JOIN and means to show all records from left table (i.e. the one that precedes in SQL statement) regardless of the existance of matching records in the right table.
LEFT JOIN 与LEFT OUTER JOIN 相同,表示无论右表是否存在匹配记录,都显示左表(即SQL 语句中的前一个)中的所有记录。
RIGHT JOIN is same as RIGHT OUTER JOIN and means opposite of LEFT JOIN, i.e. shows all records from the second (right) table and only matching records from first (left) table.
RIGHT JOIN 与 RIGHT OUTER JOIN 相同,与 LEFT JOIN 的意思相反,即显示第二个(右)表中的所有记录,并且只显示第一个(左)表中匹配的记录。
回答by Matthew Flaschen
LEFT JOINincludes every row on the left, NULL filling the right as needed. RIGHT JOINis the opposite.
LEFT JOIN包括左边的每一行,NULL 根据需要填充右边。 RIGHT JOIN则相反。