MySQL 内外连接

MySQL 内外连接

内连接:

所有满足条件的记录才会出现在结果集中;
select  emp.name,dept.addr  from  emp,dept  where  emp.deptid = dept.id
select  emp.name,dept.addr  from  emp  join  dept  on  emp.deptid = dept.id


外连接

不满足条件的记录也会出现在结果集中;包括左连接 右连接 全连接(注:mysql不支持全连接,可用左右连接 结果集  合并得到全连接)

左连接:  
 
select  emp.name,dept.addr  from  emp  left   join  dept  on  emp.deptid = dept.id
右连接:

select  emp.name,dept.addr  from  emp  right   join  dept  on  emp.deptid = dept.id

自连接:

自连接是说一个表,连接到自己。


参考文档:
http://blog.csdn.net/imzoer/article/details/8266583
http://www.cnblogs.com/ggjucheng/archive/2012/11/06/2757972.html





你可能感兴趣的:(MySQL 内外连接)