MySQL get all unique values between two columns

﹥>﹥吖頭↗ 提交于 2021-02-05 09:45:34

问题


I have a table with two columns that contain ID's. I want to query the table to show one list of each ID from the two columns.

TABLE
A | B
-----
1 | 2
2 | 3
5 | 4
6 | 2

I want the result to be:

TABLE
  A
  -
  1
  2
  3
  5
  4
  6

回答1:


Use the UNION operator

SELECT A FROM TABLE
UNION
SELECT B FROM TABLE


来源:https://stackoverflow.com/questions/22976395/mysql-get-all-unique-values-between-two-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!