1.连接的类型

1)交叉连接:是一种简单的连接,如果一个表有2条记录,另外一个有3条记录那么做连接后将会有2*3条,产生较大的结果集,这样对数据库的性能影响太大。

select * from 表1,表2

2)内连接:普通的连接,要求连接的后的表同时匹配原来的表,排除不匹配的。

select name,score from employee e,performance p where e.id=p.id;

3)外连接分为左外连接和右外连接

左外连接: 以左为主,包裹全部左边,一部分右边,右边没有的添加null

 select employee.id,name,score from employee right join performance on  employee.id=performance.id;

右外连接: 以右为主,包裹全部右边,一部分左边,左边没有的添加null

 select      employee.id,name,score    from        employee      left    join performance on  employee.id=performance.id;

4)联合

联合的概念相当于或

 select id from performance union  (all) select id from employee;

不加all时是去掉重复的,加上后是所有不管是否重复。

exists [存在]

in

=