MySQL, update multiple tables with one query

前端 未结 6 1787
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 08:00

I have a function that updates three tables, but I use three queries to perform this. I wish to use a more convenient approach for good practice.

How can I update mu

6条回答
  •  一个人的身影
    2020-11-22 08:31

    You can also do this with one query too using a join like so:

    UPDATE table1,table2 SET table1.col=a,table2.col2=b
    WHERE items.id=month.id;
    

    And then just send this one query, of course. You can read more about joins here: http://dev.mysql.com/doc/refman/5.0/en/join.html. There's also a couple restrictions for ordering and limiting on multiple table updates you can read about here: http://dev.mysql.com/doc/refman/5.0/en/update.html (just ctrl+f "join").

提交回复
热议问题