Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Deleting records

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-03-02 : 16:04:34

I have a header(oeordhdr) table and detail(oeordlin) table. They are linked by ord_type and ord_no.

Each record in the header should have at least one corresponding record in the oeordlin.

What I want to do is delete any records in the oeordlin that do not have a corresponding record in the oeordhdr.

delete
from oeordlin_sql?????

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-03-02 : 16:07:49
DELETE det
FROM oeordlin det
WHERE NOT EXISTS (SELECT * FROM oeordhdr hdr WHERE det.ord_type = hdr.ord_type AND det.ord_no = hdr.ord_no)


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -