Hi,
I have a Select query that I can't figure out how to do. There's one table that has a list of 5,000 different Dept numbers (tblDepts), and another table (tblAccess, with 12,000 rows) where users can be assigned to various departments (a user can be assigned from 0 to 5,000 depts), and a table w/ Users. (The User_ID is a foriegn key in tblAccess)
I need a query that will return a list of Depts that haven't been assigned to a specific User_ID.
I'm using the following query, but it takes 5 minutes to run:
Select D.Dept_Number
From tblDepts D
Where D.Dept_Number Not in
(Select A.Dept_Number
From tblAccess A
Where A.User_Id = '65')
I do have clustered indexes on Dept_Number in both tables, and have run DBCC ShowContig and the results aren't that bad. I'm sure there's a better way to write the query. Any ideas would be appreciated!
Thanks,
Ray
I have a Select query that I can't figure out how to do. There's one table that has a list of 5,000 different Dept numbers (tblDepts), and another table (tblAccess, with 12,000 rows) where users can be assigned to various departments (a user can be assigned from 0 to 5,000 depts), and a table w/ Users. (The User_ID is a foriegn key in tblAccess)
I need a query that will return a list of Depts that haven't been assigned to a specific User_ID.
I'm using the following query, but it takes 5 minutes to run:
Select D.Dept_Number
From tblDepts D
Where D.Dept_Number Not in
(Select A.Dept_Number
From tblAccess A
Where A.User_Id = '65')
I do have clustered indexes on Dept_Number in both tables, and have run DBCC ShowContig and the results aren't that bad. I'm sure there's a better way to write the query. Any ideas would be appreciated!
Thanks,
Ray