我有两张桌子:
表1:orders
idOrder,
Blockquote
idUser
表2:ordersinfo
idOrder,
.......,
.......
idOrder
是两个表的主键。我必须通过idUser
从这些表中删除行。我尝试了不同的方法,但没有任何帮助。
我的问题:我应该使用什么查询?
我有这个例外
MySQLIntegrityConstraintViolationException
答案 0 :(得分:1)
您需要发出两个删除声明
-- 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 = ???