Union选择ALL查询不返回所有行 [英] Union Select ALL query not returning all rows

查看:139
本文介绍了Union选择ALL查询不返回所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL版本   13.0.5081.1


联合选择所有查询应该返回两个表中的所有行,但是正在消除重复项



创建表#t1

(rid int identity(1,1),

name varchar( 10))
$


插入#t1(名称)

值('Mary'),('Jane')



创建表#t2

(rid int identity(10,1),

name varchar(10))



插入#t2(名称)

值('Mary'),('Jane')



QUERY#1


从#t1中选择[名称]

联盟从#t2中选择所有[姓名]




Mary


QUERY#2


选择摆脱,[名称]来自#t1

union select all 摆脱,[名称]来自#t2


1 Mary¥
2 Jane

10 Mary¥
11 Jane





解决方案

如果你想要两组中的行,那就是UNION ALL。


从#t1中选择[name] 
union all
从#t2中选择[name]

select rid, [名称]来自#t1
union all
select rid,[name] from#t2


SQL Version  13.0.5081.1

The union select all query is supposed to return all rows from both tables , but is eliminating the duplicates

create table #t1
(rid int identity(1,1),
name varchar(10))

insert into #t1 (name)
values ('Mary'),('Jane')

create table #t2
(rid int identity(10,1),
name varchar(10))

insert into #t2 (name)
values ('Mary'),('Jane')

QUERY #1

select [name] from #t1
union select all [name] from #t2

Jane
Mary

QUERY #2

select rid, [name] from #t1
union select all  rid, [name] from #t2

1 Mary
2 Jane
10 Mary
11 Jane


解决方案

It is UNION ALL if you want rows from both sets.

select [name] from #t1
union all 
Select[name] from #t2

select rid, [name] from #t1
union all
select   rid, [name] from #t2


这篇关于Union选择ALL查询不返回所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆