I have to update as well as insert data in MySQL in a single query. I have two tables: one is paytransactionfailure
and second is walletbalance
in which I have to first get data from paytransactionfailure
table and and update the status of this table and insert data in walletbalance
table. Is this possible in a one query.
My first table name:
paytransactionfailure
...........................................................
id fromid toid amount refund_status user_register
...........................................................
1 5 6 20 0 1
walletbalance
...............................................
id user_id balance transaction_type
...............................................
1 5 100 credit
I want this if SELECT * from paytransactionfailure WHERE refund_status='0' and user_register
='1' and fromid='5' query exists then I have to update refund_status=1 in paytransactionfailure
table and at the same time I want to insert data in walletbalance
table for fromid user like this
want this output
...............................................
id user_id balance transaction_type
...............................................
1 5 100 credit
2 5 20 credit
for this I have used below query but I have get success in updating record but I don't get success in inserting record in walletbalance.
Is this possible or I am going in a wrong direction?
UPDATE paytransactionfailure
SET `refund_status` =1
WHERE EXISTS (SELECT * from paytransaction WHERE refund_status='0' and `user_register`='1')