读书人

多条sql查询语句查出来的字段都是一样

发布时间: 2012-05-15 14:35:29 作者: rapoo

多条sql查询语句查出来的字段都是一样的 如何将数据合并
两条SQL语句可能前面一条没加条件查了个总表,第二个查了一个时间段的
select a,b from test

select a,b from test where c=1

用查询分析器查出来时分开来的,我是想只要一个列名,数据统计到一起去,如何做到?求高人指点!!!!!!!

[解决办法]
select a,b from test
union
select a,b from test where c=1

[解决办法]

SQL code
select a,b from test   union--去掉上下两个语句重复的数据行select a,b from test where c=1select a,b from test   union all--不去掉上下两个语句重复的数据行,保留两语句的所有结果航select a,b from test where c=1
[解决办法]
探讨
SQL code



select a,b from test
union--去掉上下两个语句重复的数据行
select a,b from test where c=1


select a,b from test
union all--不去掉上下两个语句重复的数据行,保留两语句的所有结果航
select a,b from test where c=1


……

读书人网 >SQL Server

热点推荐