MySQL Delete from 1 table, using multiple tables
Posted
by nute
on Stack Overflow
See other posts from Stack Overflow
or by nute
Published on 2010-04-14T22:46:55Z
Indexed on
2010/04/14
22:53 UTC
Read the original article
Hit count: 237
I would like to delete all the rows found by that query:
SELECT cart_abandon.*
FROM cart_abandon, cart_product, txn_product, users
WHERE cart_abandon.cartid = cart_product.cartid
AND cart_product.productid = txn_product.productid
AND txn_product.username = users.username
AND users.id = cart_abandon.userid
AND txn_product.txndate >= cart_abandon.abandondate
The thing to keep in mind is that the query here uses 4 different tables, however I only want to delete rows from 1 table (cart_abandon).
Is there an easy way to do that? Maybe this: ?
DELETE cart_abandon
FROM cart_abandon, cart_product, txn_product, users
WHERE cart_abandon.cartid = cart_product.cartid
AND cart_product.productid = txn_product.productid
AND txn_product.username = users.username
AND users.id = cart_abandon.userid
AND txn_product.txndate >= cart_abandon.abandondate
Is that valid? Correct?
© Stack Overflow or respective owner