有四张表
表1 表2 表3 表4
a b a c
b d c a
e e d b
f d a c
通过删选 如何得到结果
a b c d e f
------解决方案--------------------
-----------------纵向
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2014-05-30 15:54:28
-- Version:
-- Microsoft SQL Server 2012 - 11.0.2100.60 (Intel X86)
-- Feb 10 2012 19:13:17
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition: Core-based Licensing on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[表1]
if object_id('[表1]') is not null drop table [表1]
go
create table [表1]([col] varchar(1))
insert [表1]
select 'a' union all
select 'b' union all
select 'e' union all
select 'f'
--> 测试数据:[表2]
if object_id('[表2]') is not null drop table [表2]
go
create table [表2]([col] varchar(1))
insert [表2]
select 'b' union all
select 'd' union all
select 'e' union all
select 'd'
--> 测试数据:[表3]
if object_id('[表3]') is not null drop table [表3]
go
create table [表3]([col] varchar(1))
insert [表3]
select 'a' union all
select 'c' union all
select 'd' union all
select 'a'
--> 测试数据:[表4]
if object_id('[表4]') is not null drop table [表4]
go
create table [表4]([col] varchar(1))
insert [表4]
select 'c' union all
select 'a' union all
select 'b' union all
select 'c'
--------------开始查询--------------------------
select * from [表1]
union
select * from [表2]
union
select * from [表3]
union
select * from [表4]
----------------结果----------------------------
/* col
----
a
b
c
d
e
f
(6 行受影响)
*/