4

For starters: yes, I've seen there are lots of questions on combining two/multiple columns - but so far I neither found the answer to my question nor something to get me started trying further (which I did).


I have: a table consisting of two INT fields.
I want: a single column holding the distinct values of both fields.

Examle table:

| a | b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 1 | 7 |
| 2 | 3 |
| 3 | 5 |
| 5 | 7 |

My desired result would in that case be:

| 1 |
| 2 |
| 3 |
| 5 |
| 7 |

Can this be done with a single query? What would that look like?

// EDIT: some side info (which I think is irrelevant, however, I don't want to hide it):
b is always greater than a.

tfrommen
  • 183
  • 1
  • 2
  • 13

1 Answers1

6
SELECT a AS result
FROM tableX

UNION DISTINCT

SELECT b 
FROM tableX ;
ypercubeᵀᴹ
  • 99,450
  • 13
  • 217
  • 306