question

HimaP avatar image
HimaP asked

How to show 2 different table's matching value in boolean ?

I have 2 tables and both have column name FirstName. I need to find if both table FirstName match at least one value and the answer should be yes . What could be the script ?

sql-server
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered

You could try:

	IF EXISTS (SELECT 1 from dbo.Table1 t1 INNER JOIN dbo.Table2 t2 on t1.FirstName = t2.FirstName)
BEGIN PRINT 'Yes' END ELSE BEGIN PRINT 'No' END

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

HimaP avatar image HimaP commented ·

Thank you JohnM.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.