Delete subquery using EXISTS keyword

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!
 
N

Nikos Yannacopoulos

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
 

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

Similar Threads


Top