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

Delete left join query 1

Status
Not open for further replies.

44nato44

Programmer
Dec 12, 2008
115
NL
Hi

I made this query in MS Access database but have not imported my database to MS SQL but how can I get this query to work.

Delete tblAccessRights.*
From [tblAccessRights]
Left Join [tblTriSecActis]
on tblAccessRights.UserId = tblTriSecActis.UserName
Where tblTriSecActis.UserName Is NULL


I hope somebody can help me
 
Your syntax is very close. All you need to do is remove the .* part.

Code:
Delete tblAccessRights
From [tblAccessRights]
Left Join [tblTriSecActis]
on tblAccessRights.UserId = tblTriSecActis.UserName
Where tblTriSecActis.UserName Is NULL

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
If you wanted to delete all records that do not exist in the other table, this syntax will be better:
Code:
delete from tblAccessRights 
where not exists (select 1 from tblTriSecActis SA
where SA.UserName = tblAccessRights.UserID)

Read this very entertaining blog as to why
Dear From Clause


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top