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

id sal
2 10,000
3 20,000

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

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

please mark it as answer if it helps.
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[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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