SQL两列合并问题
来源:百度知道 编辑:UC知道 时间:2024/05/10 14:17:11
有个表list中有2项id1和id2
id1 id2
1 5
2 6
如何写SQL语句显示结果为id一项
id
1
2
5
6
急,在线等,谢谢
id1 id2
1 5
2 6
如何写SQL语句显示结果为id一项
id
1
2
5
6
急,在线等,谢谢
很简单
用union
就可以了
select id1 from list union select id2 from list
--可以达到你的要求并且可以过滤掉id1和id2联合起来的重复值
如果不想过滤掉重复值
select id1 from list union all select id2 from list
共同学习!
select id1 as id from table union all
select id2 as id from table