select * from 表1,表2 where 条件
# 先计算两张表的笛卡尔积,再根据用户给出的条件进行筛选
内连接:只显示两张表中互相匹配的项,其他不匹配的不显示
select * from 表1 inner join 表2 on 条件
外连接:
左外连接:不管左表中是不是匹配上都会显示所有内容
select * from 表1 left join 表2 on 条件
右外连接:不管右表中是不是匹配上都会显示所有内容
select * from 表1 right join 表2 on 条件
全外连接:mysql不支持
select * from 表1 left join 表2 on 条件
union(去重)
select * from 表1 right join 表2 on 条件
要求查询的结果必须是一个单行单列的值
连表的效率比子查询的效率要高,推荐使用
select * from 表 where 条件 = (子查询);
select * from (子查询) where 条件;
select (子查询,结果必须是一个单行单列的值) from 表
原文:https://www.cnblogs.com/wxl1025/p/11316932.html