union联合查询select * from 表 union select * from 表;
union语句必须有两条或两条以上的select组成并且具有相同的列,表达式,聚合函数
每个Select 语句中对应的目标列数据必须兼容
第一个select语句中的列名称会作为union结果集的列名称
只能使用一次 order by 和limit并放在最后一句select 后
select * from 表 union all select * from 表 order by 字段(数字) asc limit 2,3;
union all 不去重select * from 表 union all select * from a;
多表连接查询
笛卡尔积
cross join select * from 表 cross join 表;
或select * from 表1,表2;
内连接 inner join select * from 表1 inner join 表2 where 表1.字段=表2.字段;
或select * from 表1 inner join 表2 on 表1.字段=表2.字段;w
或select * from 表1,表2 where 表1.字段=表2.字段
自然连接当想连接的两个表中有相同的字段时使用
nature join
左外连接 left join select * from 表名 left join 连接表 on 表.字段=连接表.字段 以左表为主如过左表字段有空值那么用null补齐
右外连接 right join select * from 表名 right join 连接表 on 表.字段 = 连接表.字段; 以右表为主