sql UNION ALL用法详解

php中文网
发布: 2016-06-07 17:47:58
原创
5990人浏览过

union all 这个指令的目的也是要将两个 sql 语句的结果合并在一起。 union all 和 union 不同之处在于 union all 会将每一笔符合条件的资料都列出来,无论资料值有无重复。

union all 的语法如下:

[sql 语句 1]
union all
[sql 语句 2]

我们用和上一页同样的例子来显示出 union all 和 union 的不同。同样假设我们有以下两个表格,

黑色全屏自适应的H5模板
黑色全屏自适应的H5模板

黑色全屏自适应的H5模板 HTML5的设计目的是为了在移动设备上支持多媒体。新的语法特征被引进以支持这一点,如video、audio和canvas 标记。HTML5还引进了新的功能,可以真正改变用户与文档的交互方式,包括: 新的解析规则增强了灵活性 淘汰过时的或冗余的属性 一个HTML5文档到另一个文档间的拖放功能 多用途互联网邮件扩展(MIME)和协议处理程序注册 在SQL数据库中存

黑色全屏自适应的H5模板 56
查看详情 黑色全屏自适应的H5模板

 

1> create table employee( 2>     id          int, 3>     name        nvarchar (10), 4>     salary      int, 5>     start_date  datetime, 6>     city        nvarchar (10), 7>     region      char (1)) 8> go 1> 2> insert into employee (id, name,    salary, start_date, city,       region) 3>               values (1,  'jason', 40420,  '02/01/94', 'new york', 'w') 4> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (2,  'robert',14420,  '01/02/95', 'vancouver','n') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (3,  'celia', 24020,  '12/03/96', 'toronto',  'w') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (4,  'linda', 40620,  '11/04/97', 'new york', 'n') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (5,  'david', 80026,  '10/05/98', 'vancouver','w') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (6,  'james', 70060,  '09/06/99', 'toronto',  'n') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (7,  'alison',90620,  '08/07/00', 'new york', 'w') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (8,  'chris', 26020,  '07/08/01', 'vancouver','n') 3> go (1 rows affected) 1> insert into employee (id, name,    salary, start_date, city,       region) 2>               values (9,  'mary',  60020,  '06/09/02', 'toronto',  'w') 3> go (1 rows affected) 1> 2> * from employee 3> go id          name       salary      start_date              city       region ----------- ---------- ----------- ----------------------- ---------- ------           1 jason            40420 1994-02-01 00:00:00.000 new york   w           2 robert           14420 1995-01-02 00:00:00.000 vancouver  n           3 celia            24020 1996-12-03 00:00:00.000 toronto    w           4 linda            40620 1997-11-04 00:00:00.000 new york   n           5 david            80026 1998-10-05 00:00:00.000 vancouver  w           6 james            70060 1999-09-06 00:00:00.000 toronto    n           7 alison           90620 2000-08-07 00:00:00.000 new york   w           8 chris            26020 2001-07-08 00:00:00.000 vancouver  n           9 mary             60020 2002-06-09 00:00:00.000 toronto    w (9 rows affected) 1> 2> 3> select id, name from employee where name like 'c%' 4> union all 5> select id, name from employee where name like 'a%' 6> go id          name ----------- ----------           3 celia           8 chris           7 alison (3 rows affected) 1> 2> drop table employee 3> go 1>
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号