user3442289 user3442289 -4 years ago 76
SQL Question

Result two joins SQL Server

I attended interview yesterday, they asked one question from join

have table demo1 which has values A,B,C,D
have another table Demo2 which has value C,D
I want result C,D using Join

how do we do that? i tried but not able to find out solution.

can anyone of you can help me.


can anyone of you can help me.

Create table Demo1(ID char(1))
Insert into Demo1
select 'A'
Insert into Demo1
select 'B'
Insert into Demo1
select 'C'
Insert into Demo1
select 'D'

Create table Demo2(ID char(1))
Insert into Demo2
select 'A'
Insert into Demo2
select 'B'

Answer Source

Once simple approach is via a LEFT JOIN

Select D1.*
 From  Demo1 D1
 Left  Join Demo2 D2 on D1.ID=D2.ID
 Where D2.ID is null

Returns

ID
C
D
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download