sql - Select No Rows If Any Row Meets A Condition? -
how can select no rows if row in result set meets condition?
for instance:
id|somecolumn|indicator 1 | test | y 1 | test1 | y 1 | test2 | x 2 | test1 | y 2 | test2 | y 3 | test1 | y
say wanted select rows id = 1 unless there row indicator = x
currently doing this
select * sometable id = 1 , indicator = 'y' , id not in (select id indicator = 'x')
but feels clunky , feel there better way doing this. there or being overly sensitive
something ?
select * sometable id = 1 , not exists (select 1 sometable indicator = 'x')
or, if want x discriminate on same id:
select * sometable t1 t1.id = 1 , not exists (select 1 sometable t2 t1.id = t1.id , indicator = 'x')
Comments
Post a Comment