Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Items That Do Not Join In Another Table

Status
Not open for further replies.

GLSmyth

Programmer
Sep 29, 2005
11
US
This is an SQL question which might be rather simplistic, but it's just not connecting with me.

I have two tables, a customer table and a purchase table. The customer table holds not only those who have made purchases (and can be linked to the purchase table), but also prospects with no link to the purchase table.

Selecting all customers is easy, I just select the customer id in the purchase table. However, I am unable to select prospects. How do I create a select that says, "Select everyone in the Customer table that is not linked in the Purchase table"? Is this even possible? I can write the code to do this, but having it in the SQL statement would be so much cleaner.

Cheers -

george
 
Select everyone in the Customer table that is not linked in the Purchase table
SELECT C.*
FROM Customer C LEFT JOIN Purchase P ON C.CustID = P.CustID
WHERE P.CustID Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Of course, thanks so much to pointing me to what I should have known. <g>

Cheers -

george
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top