开发者

SQL Query to select only values that have No default indicator

I have a table that has the following fields: Primary Key ID Employee_ID Default_Indicator (value 'N' or 'Y') Affiliation (Student, Staff, Faculty)

An employee can be only a Student, Staff or Faculty member. Whichever they are will have the default indicator = 'Y'

Problem is that Default value for default in开发者_C百科dicator = 'N'. Sometimes users wont show up in the application since they don't have a default_Indicator set.

How do I query to find those that have a value of 'N' for Default_indicator, but doesn't have another row having Default_indicator = 'Y'

Thanks for any help.


SELECT Employee_ID
FROM [table_name] t
WHERE Default_Indicator = 'N'
    AND NOT EXISTS ( SELECT *
          FROM [table_name] t1
          WHERE t.Employee_ID = t1.Employee_ID
              AND Default_Indicator = 'Y' )

I'm not sure if I fully understand what you mean but I think this should do the trick. Try it out :)


Another solution:

ELECT Employee_ID
FROM [table_name] t
WHERE t.Default_Indicator = 'N' AND t.Employee_ID 
     NOT IN  ( SELECT t1.Employee_ID
          FROM [table_name] t1
              AND t1.Default_Indicator = 'Y' )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜