I need to update a bunch of rows in a transaction table to status 'ac'.
The rows I need to update are given by the query:
I've tried something like
but I get an error:
I know it can be done, but I'm not sure of the correct syntax..
The rows I need to update are given by the query:
Code:
SELECT transaction.id
FROM transaction
INNER JOIN transaction_item ON transaction_item.transaction_id = transaction.id
INNER JOIN product ON product.id = transaction_item.product_id
WHERE product.is_trial =1
AND transaction_item.status = 'ac'
AND transaction.status = 'pd'
I've tried something like
Code:
UPDATE transaction SET status = 'ac' WHERE transaction.id IN (
SELECT transaction.id
FROM transaction
INNER JOIN transaction_item ON transaction_item.transaction_id = transaction.id
INNER JOIN product ON product.id = transaction_item.product_id
WHERE product.is_trial =1
AND transaction_item.status = 'ac'
AND transaction.status = 'pd'
)
but I get an error:
mysql said:#1093 - You can't specify target table 'transaction' for update in FROM clause
I know it can be done, but I'm not sure of the correct syntax..