John Woo
John Woo

Reputation: 263693

Merge Result Set from Different Query in SQL

is there a way on how to merge result sets from different query? like for example

Query A

SELECT DISTINCT HighEnd FROM Chipset

    HighEnd
    ------------
    Class A
    Class B
    Class C

and

Query B

SELECT DISTINCT LowEnd FROM VideoCard

    LowEnd
    ------------
    Class X
    Class Y
    Class Z

and make it something like this

    CombinedSets
    ------------
    Class A
    Class B
    Class C
    Class X
    Class Y
    Class Z

Upvotes: 0

Views: 335

Answers (2)

My Other Me
My Other Me

Reputation: 5117

Union or Union All

SELECT DISTINCT HighEnd as CombinedSets FROM Chipset
UNION
SELECT DISTINCT LowEnd FROM VideoCard

Upvotes: 1

Jacob
Jacob

Reputation: 43209

SELECT DISTINCT HighEnd AS CombinedSets FROM Chipset
UNION
SELECT DISTINCT LowEnd AS CombinedSets FROM VideoCard

You can use UNION to combine the results. This only shows you distinct values for both. If you want duplicates, you need to use UNION ALL.

Upvotes: 2

Related Questions