Re: Problem deleting records

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Allen

Many thanks

I should have been able to do this one myself!

Jim Jones
Botswana

"Allen Browne" wrote:

I think this is what you want:

DELETE FROM Table2
WHERE EXISTS
(SELECT Candidate_ID
FROM Table1
WHERE Table1.Candidate_ID = Table2.Candidate_ID);

If subqueries are a new idea, here's an introduction:
http://allenbrowne.com/subquery-01.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jim Jones" <JimJones@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FAAEC88D-A490-45EB-A963-2D4621B9E1D8@xxxxxxxxxxxxxxxx
I have 2 tables. The first field of each table is the same - I call it
Candidate_ID - other fields are different.

In Table1, there is only one instance of each value of Candidate_ID,
whereas
in Table2 each value of Candidate_ID may occur more than once. There are
many values of Cadidate_ID in Table2 which do not occur in Table1.

For each unique value of Candidate_ID in Table1, I need to delete all
records which contain the same value of Candidate_ID in Table2.

I thought it would be easy, and since my VBA is still not so good, I have
been trying to use an SQL statement derived from the Query Design View -
so
far without success. Perhaps it can't be done with SQL.

Any help would be much appreciated

Jim Jones
Botswana


.



Relevant Pages

  • Re: 2 column pulldown
    ... Allen Browne - Microsoft MVP. ... these field heading names come from Table2 since it is a lookup and so ... Table1 of course only has a single column name ... fieldX from Table1 is pulldown revealing candidate values of Table2. ...
    (microsoft.public.access.forms)
  • Re: 2 column pulldown
    ... Allen Browne - Microsoft MVP. ... these field heading names come from Table2 since it is a lookup and so ... Table1 of course only has a single column name ... fieldX from Table1 is pulldown revealing candidate values of Table2. ...
    (microsoft.public.access.forms)
  • Re: UPDATE (SQL): multiple SET fields not allowed?
    ... Any chance of using an INNER JOIN between Table1 and Table2? ... Allen Browne - Microsoft MVP. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Problem deleting records
    ... DELETE FROM Table2 ... Allen Browne - Microsoft MVP. ... In Table1, there is only one instance of each value of Candidate_ID, whereas ...
    (microsoft.public.access.queries)
  • Problem deleting records
    ... The first field of each table is the same - I call it ... In Table1, there is only one instance of each value of Candidate_ID, whereas ... many values of Cadidate_ID in Table2 which do not occur in Table1. ... Jim Jones ...
    (microsoft.public.access.queries)