mysql中的左连接和右连接有什么区别[重复]

时间:2022-09-16 14:26:09

Possible Duplicate:
What is the difference between Left, Right, Outer and Inner Joins?

可能重复:Left,Right,Outer和Inner Joins有什么区别?

What is the difference between left joins and right joins in mysql

mysql中的左连接和右连接有什么区别

2 个解决方案

#1


29  

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相反,即显示来自第二(右)表的所有记录,并且仅匹配来自第一(左)表的记录。

#2


4  

LEFT JOIN includes every row on the left, NULL filling the right as needed. RIGHT JOIN is the opposite.

LEFT JOIN包括左侧的每一行,NULL根据需要填充右侧。 RIGHT JOIN恰恰相反。

#1


29  

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相反,即显示来自第二(右)表的所有记录,并且仅匹配来自第一(左)表的记录。

#2


4  

LEFT JOIN includes every row on the left, NULL filling the right as needed. RIGHT JOIN is the opposite.

LEFT JOIN包括左侧的每一行,NULL根据需要填充右侧。 RIGHT JOIN恰恰相反。