frosty1
asked on
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
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
delete from orders o where not exists(select * from orderitems oi where oi.orderid = o.orderid)
backup your db before tyr
delete from orders where id not in
(select orderid from orderitems )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Did you solved your problem?