PC Review


Reply
Thread Tools Rate Thread

Delete entries in TableB that are not in TableA

 
 
kikeman
Guest
Posts: n/a
 
      26th Nov 2009
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.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      26th Nov 2009
DELETE FROM TableB
WHERE OrderNo NOT IN
(SELECT DISTINCT OrderNo
FROM TableA)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"kikeman" <(E-Mail Removed)> wrote in message
news:8EEFC8B3-8599-491F-ABA1-(E-Mail Removed)...
> 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.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a “Linked Table” path be updated with VBA? Brad Microsoft Access VBA Modules 1 12th Sep 2009 07:55 PM
Delete all entries Rubicon Microsoft Outlook Discussion 2 28th Aug 2008 12:47 AM
Update TableA with data from TableB using Update Query Ellette Microsoft Access Queries 3 14th May 2008 02:58 PM
UPDATE TableB Thru TableA Diem Dang Microsoft Access Database Table Design 1 29th Aug 2003 06:11 PM
UPDATE TableB Thru TableA Diem Dang Microsoft Access Queries 1 29th Aug 2003 06:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 PM.