Reputation: 180
I have two tables:
Table1: orders
idOrder,
Blockquote
idUser
Table2: ordersinfo
idOrder,
.......,
.......
idOrder
is primary a key for two tables. I have to delete from this tables rows by idUser
. I tried different ways, but nothing helped me.
My Questions: What query, I should use?
I have this exception
MySQLIntegrityConstraintViolationException
Upvotes: 0
Views: 980
Reputation: 69564
You will need to issue two delete statement
-- Delete OrderInfo table
DELETE FROM ordersinfo
WHERE EXISTS (SELECT 1
FROM orders
WHERE orders.idOrder = ordersinfo.idOrder
AND IdUser = ???)
-- Delete Orders
DELETE FROM Orders
WHERE IdUser = ???
Upvotes: 1