首页 > 数据库技术 > 详细

MYSQL的多表查询

时间:2018-08-29 19:07:10      阅读:184      评论:0      收藏:0      [点我收藏+]
1、笛卡儿积
select * from emp,dep; 

select * from emp,dep where emp.dep_id = dep.id;

select * from emp,dep where emp.dep_id = dep.id and dep.name = "技术";

2、内连接:只取两张表有对应关系的记录

select * from emp inner join dep on emp.dep_id = dep.id;
select * from emp inner join dep on emp.dep_id = dep.id
                                                        where dep.name = "技术";
        inner join 连接两个表, where过滤条件,只取条件符合的

3、左连接: 在内连接的基础上保留左表没有对应关系的记录

select * from emp left join dep on emp.dep_id = dep.id;

4、右连接: 在内连接的基础上保留右表没有对应关系的记录

select * from emp right join dep on emp.dep_id = dep.id;

5、全连接:在内连接的基础上保留左、右面表没有对应关系的的记录

select * from emp left join dep on emp.dep_id = dep.id
union
select * from emp right join dep on emp.dep_id = dep.id;

MYSQL的多表查询

原文:http://blog.51cto.com/13764714/2166158

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!