INNER LEFT RIGHT JOIN語句
Sql代碼
CREATE TABLE `a` (
`a1` VARCHAR(10) DEFAULT NULL,
`b1` VARCHAR(10) DEFAULT NULL,
`c1` VARCHAR(10) DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8
www.2cto.com
CREATE TABLE `b` (
`a2` VARCHAR(10) DEFAULT NULL,
`b2` VARCHAR(10) DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8
創建出表,表內數據如下:
SQL語句執行結果圖片在語句的下方
Sql代碼
#inner join
SELECT A.*,B.*
FROM a INNER JOIN B ON a.a1=b.a2
www.2cto.com
Sql代碼
#left join
SELECT A.*,B.*
FROM a LEFT OUTER JOIN b ON a.a1 = b.a2
Sql代碼
#right join
SELECT A.*,B.*
FROM a RIGHT OUTER JOIN b ON a.a1 = b.a2
Sql代碼
#full outer join union
SELECT A.*,B.*
FROM a LEFT OUTER JOIN b ON a.a1 = b.a2
UNION www.2cto.com
SELECT A.*,B.*
FROM a RIGHT OUTER JOIN b ON a.a1 = b.a2
Sql代碼
SELECT A.*, B.* FROM A,B
Sql代碼
SELECT A.*,B.*
FROM a JOIN b ON a.a1 = b.a2
默認是inner join