Delete an entries that are not in

kikeman

Registered User.
Local time
Today, 14:12
Joined
Nov 20, 2009
Messages
13
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.
 
try:
Code:
DELETE FROM TableB WHERE OrderNo NOT IN (SELECT DISTINCT OrderNo FROM TableA);
 
Last edited:
If I want to view this info from Access2003 what should I need to do?
(Entries that are in TableB but not in TableA according to the "OrderNo")
 
If I want to view this info from Access2003 what should I need to do?
(Entries that are in TableB but not in TableA according to the "OrderNo")

This should list the rows, rather than deleting them.
Code:
SELECT * FROM TableB WHERE OrderNo NOT IN (SELECT DISTINCT OrderNo FROM TableA);
 

Users who are viewing this thread

Back
Top Bottom