a1 a2 a3
张三 李四 王五
张三 王五 李四
张三 赵六 王五
赵六 李四 王五
需要在三个字段中,合并查询出结果是:
张三
李四
王五
赵六
8 个解决方案
#1
select distinct a1 from tb
union
select distinct a2 from tb
union
select distinct a3 from tb
union
select distinct a2 from tb
union
select distinct a3 from tb
#2
把楼上的给简化一下:
select a1 from tb
union
select a2 from tb
union
select a3 from tb
#3
挺
#4
select a1 from tb
union
select a2 from tb
union
select a3 from tb
union
select a2 from tb
union
select a3 from tb
#5
select distinct a
from
(
select a1 as a from tb
union
select a2 as a from tb
union
select a3 as a from tb
) t
from
(
select a1 as a from tb
union
select a2 as a from tb
union
select a3 as a from tb
) t
#6
distinct效率是比较差的。
#7
union已经是去除掉重复的数据了
#8
谢谢.
#1
select distinct a1 from tb
union
select distinct a2 from tb
union
select distinct a3 from tb
union
select distinct a2 from tb
union
select distinct a3 from tb
#2
把楼上的给简化一下:
select a1 from tb
union
select a2 from tb
union
select a3 from tb
#3
挺
#4
select a1 from tb
union
select a2 from tb
union
select a3 from tb
union
select a2 from tb
union
select a3 from tb
#5
select distinct a
from
(
select a1 as a from tb
union
select a2 as a from tb
union
select a3 as a from tb
) t
from
(
select a1 as a from tb
union
select a2 as a from tb
union
select a3 as a from tb
) t
#6
distinct效率是比较差的。
#7
union已经是去除掉重复的数据了
#8
谢谢.