user793468
user793468

Reputation: 4966

display unique data from two tables

I have two tables. ProductA and ProductB.

ProductA

ID SubId

A1 112
A1 113
A1 114
B1 111
C1 113
C1 115
D1 117
D1 118
E1 114

ProductB

ID SubId

A1 112
A1 118
B1 111
B1 113
C1 114
D1 117
D1 118
E1 115
E1 116
E1 117

I want to write a query which outputs two columns ID and SubId and displays distinct SubId columns for a particular ID. So for the above tables, for column A it will display following:

ID SubId

A1 112
A1 113
A1 114
A1 118

How can I get this done?

Upvotes: 1

Views: 103

Answers (1)

invertedSpear
invertedSpear

Reputation: 11054

Assuming by saying unique, you really just mean no duplicates as per your example result, You want to use UNION

SELECT ID, SubID
FROM tblA
UNION 
SELECT ID, SubID
FROM tblb

Upvotes: 3

Related Questions