how to delete records that contain no child records

I need to delete all order records that do not container order items.

the tables are linked by the orderId on the orderItems table. So i can do the following

select * from orders o
inner join orderitems oi on o.id = oi.orderid

How can i detect which order records contain no child orderItems
frosty1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jmro20Connect With a Mentor Commented:
Delete From Orders
          Left Join OrderItems On Orders.OrderId = OrderItems.OrderId
Where OrderItems.OrderId IS NULL      
0
 
devlab2012Commented:
delete from orders o where not exists(select * from orderitems oi where oi.orderid = o.orderid)
0
 
Rajkumar GsSoftware EngineerCommented:
backup your db before tyr
delete from orders where id not in
 (select orderid from orderitems )

Open in new window

0
 
8080_DiverCommented:
I would recommend using jmro20's answer.  Among other points in its favor is the fact that it is probably going to provide the best performance.
0
 
jmro20Commented:
Did you solved your problem?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.