单独 union 个人理解除了name,还按ID进行默认排序单独 union all 不是说按组合顺序排序呢 4为何拍在3前?混用情况下 顺序为何有区别?求教…… 实在不好理解
解决方案 »
- 如何把数据库中所有表的主键更改为int identifier?
- 还是更新语句
- 100分,SQL2005数据库角色权限问题!
- 求Sql分词技术的资料
- 这个问题有几种可能,解决的办法?用户sa登陆失败,原因“未与信任的SQL server连接相关联
- 请教MSSQL数据库的网络配置!!
- 如何防止用户输入特殊SQL内容(比如'"(=等?
- 关于自动求和的(类似与SQL SERVER的触发器)
- 删除的问题,很简单,帮忙了
- 问题是一个初级的,关于MS SQL SERVER对图像的存贮。
- 文章发布系统中,我的网站文章只有1000篇,但是已经用掉100M了,怎么会这么大的?
- (SQL批量删除)应该要怎么组织更新语句才能一次更新统计?
ID NAME
3 中
1 国
2 人
4 中
对应:
4 中
3 中
=============================
ID NAME
1 国
2 人
3 中
4 中对应:
3 中
4 中
-----------order 不知道是怎么工作的 第一种情况就很蹊跷 明明3在4前 个人理解应该是 1-2-3-4
难道是按照就近原则排序的吗?1-2(就近查找下一个值)--->4-3
select id=3,name='中'
union all select 1,'国'
union select 2,'人'
union all select 4,'中' ) as t
order by name 这个例子,你看一下. select * from (
select id=3,name='中'
union all select 1,'人'
union select 2,'国'
union all select 4,'中' ) as t
order by name 看看这个你能不能想起什么.把其它几个字也都换一下,会有更多问题.
我只看到 union 树状结构 具体哪部做了什么我看不出来
好像也不是:
(select id=3,name='中'
union all select 1,'人'
union select 2,'国')
-------------------------------3 中
1 人
2 国
(select id=3,name='中'
union all select 1,'人'
union select 2,'国' ) union all (select 4,'中')
-------------------------------
2 国
1 人
3 中
4 中多加了一个()里语句,顺序完全变了 按说union all是不排序的
后边跟随的数据不排序
是直接联接上的
select id=3,name='中'
union all select 1,'国'
union all select 2,'人'
union all select 4,'中'
) as t
order by name
select * from (
select id=3,name='中'
union all select 1,'国'
union all select 2,'人'
union select 4,'中'
) as t
order by name 都排序而
select * from (
select id=3,name='中'
union all select 1,'国'
union select 2,'人'
union all select 4,'中'
) as t
order by name 只排序
select id=3,name='中'
union all select 1,'国'
union select 2,'人' 其他
select * from (
select id=3,name='中'
union all select 1,'国'
union select 2,'人'
union select 4,'中'
) as t
order by name select * from (
select id=3,name='中'
union select 1,'国'
union select 2,'人'
union select 4,'中'
) as t
order by name
select * from (
select id=3,name='中'
union select 1,'国'
union all select 2,'人'
union select 4,'中'
) as t
order by name select * from (
select id=3,name='中'
union select 1,'国'
union select 2,'人'
union all select 4,'中'
) as t
order by name
都没有排序
unoin all 没有去重union 合集后,还去掉重复的
但是按测试的结果 似乎sql server的 union怎么没有排序的功能?--------------------------------------------------------------------------------------------------在数据库中,UNION和UNION ALL关键字都是将两个结果集合并为一个,但这两者从使用和效率上来说都有所不同。UNION在进行表链接后会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。实际大部分应用中是不会产生重复的记录,最常见的是过程表与历史表UNION。如: select * from gc_dfys union select * from ls_jg_dfys 这个SQL在运行时先取出两个表的结果,再用排序空间进行排序删除重复的记录,最后返回结果集,如果表数据量大的话可能会导致用磁盘进行排序。 而UNION ALL只是简单的将两个结果合并后就返回。这样,如果返回的两个结果集中有重复的数据,那么返回的结果集就会包含重复的数据了。 从效率上说,UNION ALL 要比UNION快很多,所以,如果可以确认合并的两个结果集中不包含重复的数据的话,那么就使用UNION ALL,如下: select * from gc_dfys union all select * from ls_jg_dfys