Delete records from second table

S

sebastico

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
 
J

John Spencer

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
 
S

sebastico

John And Ken

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

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

Top