SELECT a.*, case when (SELECT count(1) FROM TableA where ColumnA = a.ColumnB)=0 then 'Y' else 'N' end as Flag FROM TableB a where ColumnC = '7974'