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.
SELECT? It's only a single query, yes. I should've writtenSELECTin my question, though. :) – tfrommen Jun 21 '16 at 10:55SELECTkeyword in the query). But no, I don't think that is possible. – ypercubeᵀᴹ Jun 21 '16 at 10:57UNION DISTINCTgives an incorrect result. JustUNIONseems correct. Any idea on this? – tfrommen Jun 21 '16 at 11:04UNIONandUNION DISTINCTshould give you the same exact result. What result did you get? – ypercubeᵀᴹ Jun 21 '16 at 11:121 1 1 2 3 5- instead of1 2 3 5 7. – tfrommen Jun 21 '16 at 11:15UNION DISTINCT? No way. – ypercubeᵀᴹ Jun 21 '16 at 11:16