2

Lets take two result sets as in: 1,2,3,5,7 and 2,4,6,7,8

In the end I want 1,2,3,4,5,6,7,8. I can not figure out how to code this in sql. Can any one give me some suggestions? I've seen some merging functions out there but having trouble implementing something simple.

ann
  • 576
  • 1
  • 10
  • 19
David
  • 41
  • 1
  • 2
  • Doing a search of `Sql merging two result sets` revealed many links with the answer. Did you try looking it up first? – Jeff Jul 23 '11 at 22:30

2 Answers2

5

You may use UNION

(SELECT id FROM table1 WHERE 1=1)
UNION
(SELECT id FROM table2 WHERE 1=1)
ORDER BY id
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
fyr
  • 20,227
  • 7
  • 37
  • 53
4

I think maybe you're thinking of UNION?

If SELECT `Column` FROM `Table` yields 1,2,3,5,7

And SELECT `Column` FROM `Table2` yields 2,4,6,7,8

Then

SELECT `Column` FROM `Table`
UNION
SELECT `Column` FROM `Table2`

yields 1,2,3,4,5,6,7,8

Paul
  • 139,544
  • 27
  • 275
  • 264
  • You are probably mistaken, the corresponding column names in UNION do not have to be identical. But the types must be compatible. – Andriy M Jul 24 '11 at 01:19