Delete Query

B

Bdavis

Unfortunetly I was unable to apply the solutions from other who had similar
problems:

Basically, I have delete query (SQL below) which is generating the error:
"Specify the table contiang the records you want to delete" and I can't get
the SQl right.

DELETE Employees.ID, dbo_persons.*
FROM dbo_persons LEFT JOIN Employees ON dbo_persons.SPID = Employees.ID
WHERE (((Employees.ID) Is Null));

And suggestions are much appreciated
 
J

John Spencer

Assumption: You wish to delete records in table in dbo_persons. You
didn't say.

DELETE
FROM dbo_Persons
WHERE SPID IN
(SELECT SPID
FROM dbo_Persons LEFT JOIN Employees
ON dbo_Persons.SPID = Employees.ID
WHERE Employees.ID is Null)

Basically the sub-query identifies all the SPID that have no matching
value in Employees table and the In comparison uses that to identify the
records to delete.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top