0

Is it possible to make the following two queries to one single query?

update customers set customer_name = 'John'  where customer_id=1;

update purchases set state='Accepted'  where customer_id=1;

customer (table)

customer_id(PK)
customer_name

purchases (table)

customer_id(FK)
product
state

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • possible duplicate of [MySQL, update multiple tables with one query](http://stackoverflow.com/questions/4361774/mysql-update-multiple-tables-with-one-query) – Nick May 15 '14 at 19:50

1 Answers1

0

You can execute them in a single transaction:

START TRANSACTION;
update customers set customer_name = 'John'  where customer_id=1;
update purchases set state='Accepted'  where customer_id=1;
COMMIT;

If something fail inside the transaction all changes are rolled back

gipinani
  • 14,038
  • 12
  • 56
  • 85
  • Thanks man!Is there any other way like joining them and then updating? –  May 15 '14 at 19:52