当前位置:Gxlcms > 数据库问题 > SQL入门之集合操作

SQL入门之集合操作

时间:2021-07-01 10:21:17 帮助过:3人阅读

union all操作符可以连接多个数据集,区别是前者去除重复项,后者保留。对于数据库而言,union all操作更加迅速,因为数据库不需要检查数据的重复性。对于连个表

技术分享技术分享

select IND type_cd, cust_id, lname name
from individual
union all
select BUS type_cd, cust_id, name
from business;

执行操作后的结果为:

技术分享

其中,18个数据来自与individual表,8个来自于business。为了更清楚的看到区别,看下面两个实例:

select a.cust_id, a.name
from business a
uinon all
select b.cust_id, b.name
from business b;

结果为

技术分享

select a.cust_id, a.name
from business a
union
select b.cust_id, b.name
from business b;

结果为

技术分享

可以很明显看出区别。

1.intersect和except操作符

我用的MySQL版本似乎没有实现这两个功能。:(

 

SQL入门之集合操作

标签:关系   exce   image   技术   执行   code   nes   div   需要   

人气教程排行