首页 > 其他 > 详细

多表查询

时间:2019-08-07 18:45:01      阅读:53      评论:0      收藏:0      [点我收藏+]
1 连表查询
select * from 表1,表2 where 条件
# 先计算两张表的笛卡尔积,再根据用户给出的条件进行筛选

内连接:只显示两张表中互相匹配的项,其他不匹配的不显示
select * from 表1 inner join 表2 on 条件
外连接:
左外连接:不管左表中是不是匹配上都会显示所有内容
select * from 表1 left join 表2 on 条件
右外连接:不管右表中是不是匹配上都会显示所有内容
select * from 表1 right join 表2 on 条件
全外连接:mysql不支持
select * from 表1 left join 表2 on 条件
union(去重)
select * from 表1 right join 表2 on 条件
2 子查询
要求查询的结果必须是一个单行单列的值
连表的效率比子查询的效率要高,推荐使用
select * from 表 where 条件 = (子查询);
select * from (子查询) where 条件;
select (子查询,结果必须是一个单行单列的值) from 表

多表查询

原文:https://www.cnblogs.com/wxl1025/p/11316932.html

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