Delete subquery using EXISTS keyword

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a table (Tbl SIR XP Reference) which has 10460 rows in it.
I have a query (Qry SIR Select XP Ref without Matching SIR) with 6258 rows
in it.
All the rows in the query are also in the table.
I want to delete from the table all rows which also exist in the query.
I tried the following code, but it wants to delete all 10460 rows from the
table and I cant understand why. Im not too familiar with the "EXISTS"
keyword so I may be using it wrong. Anyone got any advice?

DELETE *
FROM [Tbl SIR XP Reference]
WHERE EXISTS
(select *
FROM [Qry SIR Select XP Ref without Matching SIR]
WHERE [Qry SIR Select XP Ref without Matching SIR].SOFTWARE_ID = [Tbl SIR
XP Reference].SOFTWARE_ID);

thanks for your help!
 
Try this:

DELETE * FROM [Tbl SIR XP Reference]
WHERE [Tbl SIR XP Reference].SOFTWARE_ID In (SELECT SOFTWARE_ID FROM [Qry
SIR Select XP Ref without Matching SIR]);

HTH,
Nikos
 
Back
Top