Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Only Differences

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-03 : 09:16:02
Allen Myers writes "This might be a simple question as my SQL knowledge is minimal. I'm trying to figure out how to get a query to return only the records that do not exist in a particular query the original is compared against, with a twist... read on.

For instance, I have a table called "Users" and a table called "Orders". I'd like to generate a query that shows me only users that have NO associated orders yet.

I know I can use the NOT IN clause in some manner like:

SELECT Users.UserID
FROM Users
WHERE Users.UserID NOT IN (SELECT Orders.UserID FROM Orders);

(I'm using Access with JetSQL so bear with me if my syntax is off a bit.)

Now, for the twist. Let's say the "Orders" table is actually a query. And the "Orders" query takes about 5-7 seconds to generate itself once. From my understanding, the "Orders" query will be ran once for each record compared to in the "Users" table. ACK! If I have about 300 users, that could easily add up to 30 minutes to run the query!!!

Isn't there a simpler/faster way to just compare against the "Orders" query once so I only have to wait 5-7 seconds for it to run once!?!?


Thanks in advance."
   

- Advertisement -