OK, let's say I have a table with staffid, protocolid, userrightid and projectid where those four together are unique. I want a query that gives me the staffid (which can be in the table multiple times) for every staffid that has ONLY a certain userrightid within a certain projectid. To be specific, only userrightid=100 where projectid=3. I have done this with three subqueries (because I then use that StaffID to query from another table), but am trying to do away with subqueries. So, if a staffid has four entries and three of them have userrightid=100, but one has userrightid=3, then I do not want them in my list. I believe this query is correct
it just feels kludgy to me. Any thoughts?
wb
Code:
SELECT distinct FirstName,LastName,Login, StaffID
FROM db.dbo.tblStaff
where StaffID in (
select distinct staffid
from [db].[dbo].[tblStaffProtocol]
where StaffID in
(
SELECT [StaffID]
FROM [db].[dbo].[tblStaffProtocol]
WHERE ProjectID=3
and UserRightID=100
)
AND StaffID not in
(
SELECT DISTINCT [StaffID]
FROM [db].[dbo].[tblStaffProtocol]
where UserRightID<>100
and ProjectID=3
)
)
it just feels kludgy to me. Any thoughts?
wb