内连接
内连接使用关键字INNER JOIN 也可以简写成JOIN;内连接只返回两个表中匹配的数据。
SELECT a.id, a.name,b.price
FROM table1 AS a INNER JOIN table2 AS b
ON a.id = b.id;
外连接
左外连接 用关键字LEFT OUTER JOIN 表示 也可以简写为LFFT JOIN。
以左边的表为主,返回左表的全部数据行,对于右表,如果没有匹配的数据则返回为空。
SELECT a.id,a.name,b.price
FROM table1 AS a LEFT JOIN table2 AS b
ON a.id=b.id;
右外连接
右外连接用关键字 RIGHT OUTER JOIN 表示,也可以简写为RIGHT JOIN
以右边的表为主,返回右表中的全部数据行,对于左表,如果没有匹配的数据则返回为空。
SELECT a.id,a.name,b.price
FROM table1 AS a RIGHT JOIN table2 AS b
ON a.id=b.id;