David
David

Reputation: 41

Sql Merging two result sets

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.

Upvotes: 2

Views: 8478

Answers (2)

Paul
Paul

Reputation: 141829

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

Upvotes: 4

fyr
fyr

Reputation: 20859

You may use UNION

(SELECT id FROM table1 WHERE 1=1)
UNION
(SELECT id FROM table2 WHERE 1=1)
ORDER BY id

Upvotes: 5

Related Questions