简体   繁体   中英

How to check if a record in a table also exists in another table or not in MYSQL

I have two tables "order_manager" and "aamarpay". Both the table has a column named "transaction_id". It is a 10 character long randomly generated string. I'm trying to verify if a payment is made successfully or not. If the payment is successful the transaction_id from "order_manager" table would also exist in the "aamarpay" table. Here are the structures of the tables: order_manager aamarpay

If the condition returns true then I would update "payment_status" from "order_manager" table to "successful".

Test this:

UPDATE order_manager
SET payment_status = 'successful'
WHERE EXISTS ( SELECT NULL
               FROM aamarpay
               WHERE aamarpay.transaction_id = order_manager.transaction_id )
-- AND payment_status <> 'successful'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM