chmouel kalifa
chmouel kalifa

Reputation: 129

Delete rows in one table with query in another table

I have 2 tables in my database.

table customer with ID,firstName,lastName,address...

and table orders with id, idCustomer...

and I want to delete all the orders of the customers where the first name is "john"

How I write the command?

thanks

Upvotes: 1

Views: 44

Answers (2)

Josh Fierro
Josh Fierro

Reputation: 140

Delete From
    orders 
Where
    Orders.firstName In 
        (Select
            firstName 
        From
            customers
            Inner Join orders On customers.ID = orders.idCustomer
        Where
            customers.firstName = "john")

Upvotes: 0

Code Different
Code Different

Reputation: 93161

DELETE o
FROM        Orders   o
INNER JOIN  Customer c ON o.idCustomer = c.ID
WHERE       c.firstName = 'john'

Upvotes: 3

Related Questions