sql - Stop returning multiple similar rows on joins -
i have following scenario in sqlite.
tablea id ----- 1 | 2 | 3 | table b id | aid |tag ---------------- 1 | 1 | hide 2 | 1 | show 3 | 2 | null 4 | 3 | show
table b has column aid ids of table a.
in example above table id: '1' has -> table b id of '1' , '2' , tags 'hide' , 'show' attached it.
i looking sql return, in example above, table ids: '2' , '3'. basically, tablea id: '1' has 'hide' tag attached it, don't return (even though has show tag attached it)
the sql using (excuses names, quick example)
select a.id a_id, b.id b_id, b.tag tag table left join table b on a.id = b.aid , b.tag != 'hide'
the problem sql it's still returning
a_id | b_id | tag ------------------------------- 1 | 2 | show
i'm tad stuck , appreciated. i'm not 100% sure how work on google search. closest got question how return 1 row if multiple duplicate rows , still return rows not duplicates? couldn't work out how group here.
you use condition exists
operator:
select a.id a_id, b.id b_id, b.tag tag table_a left join table_b b on a.id = b.aid not exists (select * table_b bin bin.aid = a.id , bin.tag = 'hide')
Comments
Post a Comment