简体   繁体   English

将mysql中的行从一个表更新到另一个表

[英]Update rows in mysql from one table to another

I'm trying to run a query that updates rows from one table to another. 我正在尝试运行一个查询,以将行从一个表更新到另一个表。 I want to take the values from shopping_cat_id and put them into existing rows in the table merchants where the ids match. 我想从shopping_cat_id中获取值,并将其放入ID匹配的表商人的现有行中。

here is my query thats giving me error 1064.. 这是我的查询,多数民众赞成在给我错误1064。

UPDATE `merchants` SET `category_id`=[shopping_cat_id] WHERE merchants.id = shopping.shopping_id


(SELECT shopping_id, shopping_cat_id FROM shopping)

Try this: 尝试这个:

UPDATE merchants m 
    inner join shopping s on 
               m.id = s.shopping_id
   SET m.category_id=s.shopping_cat_id

It should have some where clause of course. 当然应该有一些where子句。 Unless you want to update all. 除非您要全部更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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