MySQL update join with limit

后端 未结 3 2123
长情又很酷
长情又很酷 2021-02-15 06:05

I would like to know how to update a table, with values from another table, by the trick is I need to set a limit because I have thousands of rows to update, and PHPmyadmin can\

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 06:46

    You can try it this way

    UPDATE wp_postmeta t JOIN
    (
        SELECT p.meta_id, m.newmap
          FROM wp_postmeta p JOIN wp_map m
            ON p.meta_value = m.oldmap
         ORDER BY p.meta_id
         LIMIT 100
    ) s
       ON t.meta_id = s.meta_id
      SET t.meta_value = s.newmap;
    

    Here is SQLFiddle demo

提交回复
热议问题