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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need help with SQL Query

Author  Topic 

ljp099
Yak Posting Veteran

79 Posts

Posted - 2003-11-03 : 19:17:24
I have two tables, tblBizOwners and tblCustomers. When new business signup, they are added to tblCustomers and tblBizOwners. When customers signup they are added to only tblCustomers. Therefore, tblBizOwners has a foreign key to tblCustomers, CustomerID (which is the primary key for tblCustomers). What I need to do is show a recordset of only Customers which are not in tblBizOwners. Sql query should be something like this, but I cant figure it out (I think a having clause might work but am not sure)

Select C.*,B.CustomerID from tblCustomers C, tblBizOwners B Where tblBizOwners.CustomerID <> c.CustomerID

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-03 : 19:20:31
SELECT *
FROM tblCustomers
WHERE CustomerID NOT IN (SELECT customerID FROM tblBizOwners)

Tara
Go to Top of Page

ljp099
Yak Posting Veteran

79 Posts

Posted - 2003-11-03 : 19:39:03
Thanks Tara. That did it. I wasnt familiar with the NOT IN clause.
Go to Top of Page
   

- Advertisement -