query unique database with condition followed SQL Server -


i have table this:

claim      |    flag -------------------- 2657       |    5 2657       |    5 2657       |    5 2657       |    2 2659       |    5 2659       |    5 2659       |    5 

i want query records condition claim has flag '5' , not have flag = '2' either. example, in case: claim 2657 has flag '5' has flag '2' well. skip it. query claim '2659'.

please me write query in sql server meet condition.

this relational division no remainder (rdnr) problem. see article dwain camps provides many solution kind of problem.

sql fiddle #1

select s.claim sampledata s s.flag in(5) group s.claim having     count(distinct s.flag) = 1     , count(distinct s.flag) = (         select              count(distinct flag)          sampledata          claim = s.claim     ) 

if want specify record shouldn't have flag = 2, do:

sql fiddle #2

select distinct s.claim sampledata s     s.flag in(5)     , not exists(         select 1 sampledata claim = s.claim , flag = 2     ) 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -