[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

select statement with sub query

I have what look like a very simple select query statement
with one sub query, but for some reason, it takes a long
time to come up (1+ min).

select empid, lname, fname from table1
where empid not in (select empid from table2 where HireDate = '01/1/2004')
order by empid.

How can I fix this query so that it would be better or more optimized?

** when I run the sub query on QA, it returns like 10 records, could that
be the cause?
0
graphix03
Asked:
graphix03
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
How about...

select empid, lname, fname
from table1
inner join table2 on table1.SomeID = table2.SomeID
where table2.HireDate = '01/1/2004'
order by table1.empid
0
 
graphix03Author Commented:
But will it do the part I asked for which is where empid in table1 NOT IN table2?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
... oops, forgot to switch signs around ...

where table2.HireDate <> '01/1/2004'
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now