sqlite - Returning column indicating row existence in another table -
sqlite3
i have 2 tables, table1 , table2.
both of these tables have column called name.
i query table2 , return name column. in addition, return column containing values 1 or 0 depending on whether rows in table1 contain same value name.
what efficient way this?
i'm looking like:
select name, if exists (select * table1 table1.name = table2.name) 1 else 0 table2
sorry, i'm not familiar sqlite, should work you. trick left outer join , comparison on joined table.
select table2.name, case when table1.name not null 1 else 0 end table2 left outer join table1 on table1.name = table2.name
i'm not sure case
syntax best if more familiar conditionals in sqlite can clean part up.
Comments
Post a Comment