Delete entries in TableB that are not in TableA

K

kikeman

Hi,

I have two tables: TableA and TableB they both have a column called
"OrderNo" (same type and info, of course), I would like to delete those
entries in TableB that ARE NOT in TableA according to the "OrderNo".

"OrderNo" is the Primary Key in TableA, but it is allow to have duplicates
in TableB of "OrderNo"

It is to say, I would have in TableB "OrderNo" values only if they exist in
TableA, now I want to avoid to have "OrderNo" in TableB that does no exist in
TableA.

What would SQL command to do this?
I am using OleDB in C#.

Thanks,
Enrique.
 
D

Douglas J. Steele

DELETE FROM TableB
WHERE OrderNo NOT IN
(SELECT DISTINCT OrderNo
FROM TableA)
 

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

Unmatch query help 7
Look up value in table 6
extraction. 2
Union Query Problem 2
delete Using Join Statement 4
Not showing repeated records 2
Delete using join statement 4
change data in FE but not saved to BE 3

Top