1.内连接:
内连接两张表,并且只获取满足两表连接条件的数据。
(主:左表为emp,右表为dept)
内连接写法:
select * from emp e inner join dept d on e.dept_id=d.dept_id
等于
select * from emp e,dept d where e.dept_id=d.dept_id
2.左连接
对于左外连接来说的话,连接条件当中,如果出现满足条件的左表的数据在右表中没有相应匹配时,需要把相应的右表字段填充NULL值。
左连接的写法:
select * from emp e left join dept don e.dept_id=d.dept_id
等于
select * from emp e,dept d where e.dept_id=d.dept_id(+)
3.右连接
右外部连接与左外连部接相反,将会被填充NULL值的是左表的字段。也就是说右外部连接的主体是右表,左表来配合。
右连接的写法:
select * from emp e right join dept d on e.dept_id=d.dept_id
等于
select * from emp e,dept d where d.dept_id=e.dept_id(+)
4.全外连接
全外部连接是左外部连接和右外部连接的合集。也就是既包括左外部连接的结果集,也包括右外部连接的结果集。
全外连接的写法
select * from emp e full outer join dept d on e.dept_id=d.dept_id
查询一个字段在表中出现不止一次
例:name字段重复超过两次的记录
select name from table group by name having count(*) > 2;