一 内连接( inner join)
1、多表中同时符合某种条件的数据记录的集合 (取两表公共部分)
2、inner join 可以缩写成 join
例如: select * from A,B WHERE A.id=B.id 或者 select * from A inner join B on A.id=B.id
内连接分为三类:{
(1)等值连接: on A.id=B.id
(2) 不等值连接: on A.id>B.id
(3) 自连接: select * from A T1 inner join A T2 on T1.id = T2.pid
}
二 外连接(left join、right join)
1、左外连接: left join ,以左表为主,先查询出左表,然后按照on 后面的关联条件匹配右表,没有匹配到的用null 填充
2、右外连接: 同理
三 联合查询(union、union all)
就是把多个结果集集中在一起,union前的结果为基准,需要注意的是联合查询的列数要相等,相同的记录行会合并
注:如果使用union all , 则不会合并重复的记录行,效率方面,union也要高于union all
例如 : select * from A union select * from B union...
四 嵌套查询(子查询)
select * from A where id in (select id from B)
五 交叉连接(cross join)【笛卡尔积】
select * from A,B(,C)或者select * from A cross join B(cross join c)
注:交叉连接查询没有任何关联条件,结果是笛卡尔积,结果集很大,没有意义,所以很少使用