Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can we compare two table columns records using this logic in case statement

SQL
update Table1 set Description=
(
case
when (select Column1 from Table1 where Column1 IN (select Column2 from Table2) )  then 'data is match'
else 'Data is not match'  end
)
Posted
Updated 22-Feb-15 7:26am
v2

If this is SQL Server, I'd use a LEFT OUTER JOIN instead. Subqueries and especially IN on subqueries perform very poorly and should not be used when a JOIN will do the trick.

SQL
UPDATE #Table1 
SET [Description]=
  CASE 
    WHEN #Table2.[Column1] IS NOT NULL THEN 'data is match'
    ELSE 'Data is not match'
    END
FROM #Table1 
LEFT OUTER JOIN #Table2
ON #Table1.[Column1]=#Table2.[Column1]
 
Share this answer
 
v2
Comments
Kuthuparakkal 22-Feb-15 17:34pm    
my 5+
You should be able to do that using EXISTS:
SQL
update Table1 set Description=
(
case
when exists(select * from Table1 where Column1 IN (select Column2 from Table2) ) then 'data is match'
else 'Data is not match' end
)
 
Share this answer
 
Comments
Rajnish D mishra 22-Feb-15 13:25pm    
THANKS IT WORKS FINE

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