Monday, 15 July 2013

sql - Resultset that shows if one row is in a table or not -



sql - Resultset that shows if one row is in a table or not -

i have 2 tables , b. relationship has_many b.

rows in can in b, or not.

so, how can retrieve rows in a, , have field in resultset says each row if it's in b or not?

for example, has these ids: 1, 2, 3, 4, 5

and b has these a_ids: 1, 2, 3

so result set be:

1 true 2 true 3 true 4 false 5 false

i utilize postgresql, maybe it's irrelevant.

select id, case when exists (select * b b.a_id = a.id) 'true' else 'false' end inb

sql postgresql activerecord

No comments:

Post a Comment