连接查询通常使用在业务逻辑比较复杂、多张表的查询中,主要有内连接、外连接、交叉连接。
示例:两张表username、userage
一:内连接(自然连接)
关键字:[inner] join on
select * from username join userage on username.id = userage.id
二:外连接
1.左外连接
关键字:left [outer] join on
select * from username left join userage on username.id = userage.id
2.右外连接
关键字:right [outer] join on
select * from username right join userage on username.id = userage.id
3.全外连接
关键字:full [outer] join on
select * from username full join userage on username.id = userage.id
折腾了半天,原来MySQL不支持全外连接
三:交叉连接
关键字:cross join
select * from username cross join userage