Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,
I want sql query for compare two tabled. Add one column. Column name is status. If it is matched status is matched. Otherwise unmatched.
Posted
Updated 12-Jun-13 6:46am
v2
Comments
Amol_B 12-Jun-13 3:22am    
can you elaborate your question
jhon123 2 12-Jun-13 3:30am    
table1
Id Name Address Date Month Year
1 sony Hyd 10 06 2013
2 jhon Blr 5 06 2013
3 Ravi Hyd 6 06 2013

table2
id sal
2 10,000
3 20,000

O/P:
id Status Name Address Sal
1 Un_matched sony Hyd 0
2 matched jhon Blr 10,000
3 matched Ravi Hyd 20,000
Amol_B 12-Jun-13 4:48am    
please mark it as answer if it helps.
gvprabu 12-Jun-13 5:24am    
Why are you asking same Questions more than once?

You have to user FULL OUTER JOIN
here is the query

SQL
SELECT table1.id, 
CASE WHEN table2.sal IS NULL then 'unmatched'
ELSE 'matched' END  AS status,
table1.name,table1.address
 FROM table1 FULL OUTER JOIN table2 ON TABLE1.id = tables2.id 


please mark it as answer if it helps.
 
Share this answer
 
Check your table structure if it's right. I don't see a reason to have salary in table2. Anyway, You can get a start from here[^]
 
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