Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to join two tables where i need only records which are not common in both table.. which join need to be used??? or how this can be done????
Posted
Comments
ArunRajendra 27-Feb-14 22:26pm    
Give the table design.
rhl4569 27-Feb-14 22:43pm    
1st table
user id,username,first name, lastname
2nd table
orderid,ordername,userid
Peter Leow 27-Feb-14 22:55pm    
What output do you want?

check 'Outer Excluding JOIN' in this link

Visual Representation of SQL Joins[^]
 
Share this answer
 
Comments
King Fisher 27-Feb-14 23:36pm    
nice link george
george4986 27-Feb-14 23:46pm    
thanks K_F ;-)
rhl4569 27-Feb-14 23:50pm    
thanks george sir.. nice link
george4986 27-Feb-14 23:56pm    
happy to hear u find ur answer.
Good luck ;-)
lets say first table A and second table B,

select *
from A full outer join B
on A.[user id] = B.[userid]
where A.[userid] is null or B.[userid] is null

Or to see the result better:

select A.[userid], A.[username], A.[first name], A.[lastname], B.[orderid], B.[ordername]
from A left join B
on A.[user id] = B.[userid]
where B.[userid] is null
UNION ALL
select B.[userid], A.[username], A.[first name], A.[lastname], B.[orderid], B.[ordername]
from B left join A
on B.[user id] = A.[userid]
where A.[userid] is null
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900