|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Select from one table which is not in another
I am trying to select records from a vendor table which is not in a vendor delete table.
I am not allowed to add columns to any of the tables and i am not allowed to delete any. so i decided to make a delete table and select everything that is not in is. this is what i have and i have to base the select statment on 4 colums rather then one ID as usuall. Can someone tell me what is wrong here and help me with this. SELECT TOP 100 PERCENT CompanyID, DivisionID, DepartmentID, VendorID, VendorName, AccountNumber FROM dbo.VendorInformation WHERE (SELECT * FROM dbo.VendorsDeleted WHERE dbo.VendorInformation.VendorID <> dbo.VendorsDeleted.VendorID AND dbo.VendorInformation.DepartmentID <> dbo.VendorsDeleted.DepartmentID AND dbo.VendorInformation.DivisionID <> dbo.VendorsDeleted.DivisionID AND dbo.VendorInformation.CompanyID <> dbo.VendorsDeleted.CompanyID) ORDER BY VendorName |
|
#2
|
|||
|
|||
|
Code:
SELECT CompanyID, DivisionID, DepartmentID, VendorID, VendorName, AccountNumber FROM dbo.VendorInformation WHERE not exists (select * from FROM dbo.VendorsDeleted WHERE dbo.VendorInformation.VendorID = dbo.VendorsDeleted.VendorID AND dbo.VendorInformation.DepartmentID = dbo.VendorsDeleted.DepartmentID AND dbo.VendorInformation.DivisionID = dbo.VendorsDeleted.DivisionID AND dbo.VendorInformation.CompanyID = dbo.VendorsDeleted.CompanyID) ORDER BY VendorName |
|
#3
|
|||
|
|||
|
Thanks
Thank you. That worked perfectly.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Select from one table which is not in another |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|