Reputation: 4306
I have a use case at which i need to update only one record based on different conditions, the problem is those conditions retrieve many record, so the update statement update all of the records every time,
UPDATE t_wallet_log wallet_log
LEFT JOIN t_end_user enduser
ON enduser.f_id=wallet_log.f_end_user_id
set wallet_log.f_txn_status = 'successful'
WHERE enduser.f_ref_number='ugY-227'
AND wallet_log.f_amount=1000
AND wallet_log.f_txn_kind='cr'
I tried almost every thing i know but no luck
Upvotes: 1
Views: 83
Reputation: 412
Please try below query.
UPDATE wallet_log set wallet_log.f_txn_status = 'successful' where id=(
select p1.id from ( select wallet_log.id from t_wallet_log wallet_log
LEFT JOIN t_end_user enduser
ON enduser.f_id=wallet_log.f_end_user_id
WHERE enduser.f_ref_number='ugY-227'
AND wallet_log.f_amount=1000
AND wallet_log.f_txn_kind='cr' order by id desc limit 1)p1);
This will help you.
Upvotes: 2