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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -