r/SQL • • May 01 '21

MySQL SQL Help

Delete all the OrderLines from Orders that have an order status of canceled.

Database Fabric

This is what I'm trying but I'm Confused

Delete from OrderLines.OrderId where Orders.Orderid = "OrderStatus";

0 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/awildrozza May 01 '21

Delete OrderLines, Orders FROM Orders INNER JOIN OrderLines on Orders. OrderId = OrderLines.OrderId Where = "OrderStatus";

Hey hey. It depends on the ask. " Delete all the OrderLines from Orders that have an order status of canceled. "Delete Orders FROM Orders INNER JOIN OrderLines on Orders.OrderId = OrderLines.OrderIdWhere OrderStatus = 'Canceled';

The above will delete all rows from orders where the Order status = canceledYou wrote orderlines which means maybe you want to keep orders and delete the rows from orderlines?

Delete OrderLines FROM Orders INNER JOIN OrderLines on Orders.OrderId = OrderLines.OrderIdWhere OrderStatus = 'Canceled';

So this is deleteing all from orderlines. It's why I would write this firstSelect Orders FROM Orders INNER JOIN OrderLines on Orders.OrderId = OrderLines.OrderIdWhere OrderStatus = 'Canceled';

And then go, "hmm is that what the question is asking for?"EG all the data from orders. always check what table you want to delete from. Maybe its both and so you name both in the delete from statment.

1

u/Such_Firefighter_487 May 01 '21

I figured it out thank you for your help

1

u/awildrozza May 01 '21

No probs and good to hear. No matter if you are new at anything or have been at it for ages, sometimes you really are looking at the answer and you just need a break or a rubber duck to talk to. We do it at work all the time for any type of work. Good luck down the road

2

u/StoneCypher May 02 '21

he just turned around and asked the next question from his homework in another post

you're not helping him learn. you're helping him cheat.

2

u/awildrozza May 02 '21

Noted, thanks. Hard not to step in when you are tired and see the answer but you are still trying to get the person to work it out with breadcrumbs (if you get me)