PC Review


Reply
Thread Tools Rate Thread

Delete records from second table

 
 
sebastico
Guest
Posts: n/a
 
      28th May 2010
Hello
I have two Tables.
tblMain(MainID)
tblSec(FamID, Group, MainID)
MainID has same attribute in both tables
tblMain has the correct records.

How can I delete all records from tblSec not present in tblMain? Could you
tell me the kind of query. I'm studying Relational Algebra by myself and this
example would help me to learn
Thanks in advance
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      28th May 2010
Do you want to delete the records from the table or just SHOW the records?

SELECT tblSec.*
FROM tblSec INNER JOIN tblMain
ON tblSec.MainID = tblMain.MainID


DELETE
FROM TblSec
WHERE MainID NOT IN (SELECT MainID FROM tblMain)

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

sebastico wrote:
> Hello
> I have two Tables.
> tblMain(MainID)
> tblSec(FamID, Group, MainID)
> MainID has same attribute in both tables
> tblMain has the correct records.
>
> How can I delete all records from tblSec not present in tblMain? Could you
> tell me the kind of query. I'm studying Relational Algebra by myself and this
> example would help me to learn
> Thanks in advance

 
Reply With Quote
 
 
 
 
sebastico
Guest
Posts: n/a
 
      2nd Jun 2010

John And Ken

Many thanks for you help.
John your sql code works and the information by Ken is very useful as well
"John Spencer" wrote:

> Do you want to delete the records from the table or just SHOW the records?
>
> SELECT tblSec.*
> FROM tblSec INNER JOIN tblMain
> ON tblSec.MainID = tblMain.MainID
>
>
> DELETE
> FROM TblSec
> WHERE MainID NOT IN (SELECT MainID FROM tblMain)
>
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
>
> sebastico wrote:
> > Hello
> > I have two Tables.
> > tblMain(MainID)
> > tblSec(FamID, Group, MainID)
> > MainID has same attribute in both tables
> > tblMain has the correct records.
> >
> > How can I delete all records from tblSec not present in tblMain? Could you
> > tell me the kind of query. I'm studying Relational Algebra by myself and this
> > example would help me to learn
> > Thanks in advance

> .
>

 
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
Delete records from table 1 which match records from table 2 Matilda Microsoft Access 7 27th Mar 2009 12:25 AM
how do you delete records or update records in a link table. =?Utf-8?B?SGVscG1l?= Microsoft Access Queries 2 18th Aug 2005 05:12 PM
select all records on one table but limit records from 2nd table =?Utf-8?B?am9hbg==?= Microsoft Access Queries 8 3rd Nov 2004 02:38 AM
Choose query columns from a table based on records in a second table. Liz Camel Microsoft Access Form Coding 2 15th May 2004 03:32 AM
How to delete records from the original table while randomly selecting the records CaribSoft Microsoft Access Queries 2 5th Feb 2004 10:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:13 AM.