?
Solved

correlation subquery.

Posted on 1998-09-28
3
Medium Priority
?
413 Views
Last Modified: 2011-10-03
I have two tables of data: Jobs and Invoices. Essentially, invoices is a subset of jobs. How can I create a query which will list the jobs that do *not* have a corresponding invoice?  
0
Comment
Question by:zzchoffm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
chewhoung earned 200 total points
ID: 1963742
Try this:
select * from Jobs where Jobs.JobId not in (select JobiD from Invoice)

0
 

Expert Comment

by:dtburdick
ID: 14652633
For anyone reading this thread, this is a very slow way of doing it.  You are better off doing an outer join and then adding to the clause where the Second ID Is Null.  I increased a 10 minute query to 2 seconds doing this once.

Ie.

SELECT Jobs.*
FROM Jobs LEFT JOIN Invoices ON Jobs.JobID = Invoices.JobID
WHERE (((Invoices.InvoiceID) Is Null));

or in old style SQL

SELECT Jobs.*
FROM Jobs, Invoices
WHERE Jobs.JobID *= Invoices.JobID
AND Invoices.InvoiceID Is Null
0
 

Expert Comment

by:dtburdick
ID: 14652640
Um, duh.  I mean I DECREASED the query time, not increased. :)
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question