sql server - Add a column to table a, if the values exist in table a and table b -
i know how check if values exist in both table, how can add column indicate find something
select name, id table_a ta exists (select 1 table_b tb ta.id = tb.id)
result
name id 1 123 2 234 3 345
what want
name id exists 1 123 y 2 234 n 3 345 n
you can use exists criteria in case statement:
select name, id, case when exists (select 1 table_b tb ta.id = tb.id) 'y' else 'n' end [exists] table_a ta
Comments
Post a Comment