一、INNER JOIN
用法:
select column_name(s)
from table 1
INNER JOIN table 2
ON
table 1.column_name=table 2.column_name
例子:
两个表:three,user
select* from three inner join user;
select* from three inner join user on three.id = user.id;
二、LEFT JOIN
用法:
select column_name(s)
from table 1
LEFT JOIN table 2
ON table 1.column_name=table 2.column_name
例子:
select * from three left join user on three.id=user.id;
三、RIGHT JOIN
用法:
select column_name(s)
from table 1
RIGHT JOIN table 2
ON table 1.column_name=table 2.column_name
例子:
select * from three right join user on three.id=user.id;
四、FULL OUTER JOIN
用法:
select column_name(s)
from table 1
FULL OUTER JOIN table 2
ON table 1.column_name=table 2.column_name
例子:
select * from three full outer join user on three.id=user.id;
mysql 报错不支持full join ,但是可以用下面的这种写法取代:
select * from three left outer join user on three.id=user.id union select * from three right outer join user on three.id=user.id;
参考资料:
https://www.cnblogs.com/reaptomorrow-flydream/p/8145610.html