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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete multiple records based on data from another table 1

Status
Not open for further replies.

d1novak

Instructor
Joined
Jul 21, 2003
Messages
27
Location
US
I have 2 tables tblCOMPANY and tblCOMPANY_ACCESS. TBL_COMPANY has COMPANYID and Sales_Division. tblCOMPANY_ACCESS has COMPANYID and USERID. I need to Delete all records in tblCOMPANY_ACCESS where tblCOMPANY.SALES_DIVISION='Enterprise' and TBL_COMPANY_ACL.USERID='1234'

I tried the following but all records were deleted. yikes!

DELETE FROM tblCOMPANY_ACCESS
WHERE EXISTS
(SELECT COMPANYID,'1234'
FROM tblCOMPANY
WHERE SALES_DIVISION='Enterprise')

any help is greatly appreciated.
 
Try
Code:
delete T from tblCompany_Access T 
inner join TblCompany TC on T.CompanyID = TC.CompanyID where TC.Sales_Division = 'Enterprise' 
and T.UserID = '1234'

PluralSight Learning Library
 
Thank you markros!
works Great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top