简体   繁体   English

无法从 select 更新

[英]impossible to update from a select

Hi i ve got two tables like this:嗨,我有两张这样的桌子:

mysql> describe tb_data_iae;
+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| id_dialecte        | int(11)      | NO   | PRI | NULL    | auto_increment | 
| nb_champs          | tinyint(4)   | NO   |     | 0       |                | 
+--------------------+--------------+------+-----+---------+----------------+

and

mysql> describe tb_dialecte;
+-------------------+--------------+------+-----+------------+----------------+
| Field             | Type         | Null | Key | Default    | Extra          |
+-------------------+--------------+------+-----+------------+----------------+
| id_dialecte       | int(11)      | NO   | PRI | NULL       | auto_increment |
| nb_champs         | tinyint(4)   | NO   |     | 0          |                | 
+-------------------+--------------+------+-----+------------+----------------+

I try to update first table "nb_champs" field from the same field coming from the second table我尝试从来自第二个表的同一字段更新第一个表“nb_champs”字段

mysql> update tb_data_iae 
       set nb_champs=tb_dialecte.nbchamps  
      from tb_dialecte 
      where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte;

ERROR 1064 (42000): You have an error in your SQL syntax;错误 1064 (42000):您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from tb_dialecte where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte' at line 1检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“from tb_dialecte where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte”附近使用正确的语法

I don't know how to debug this, as I try many queries but no ones works and the error message is pretty much the same everytime as the one above...我不知道如何调试这个,因为我尝试了很多查询但没有一个有效,并且错误消息每次都与上面的几乎相同......

Thx for help !谢谢帮助!

update tb_data_iae set nb_champs=(SELECT tb_dialecte.nbchamps 
from tb_dialecte 
where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte);

Though I'd ask why store the same values in two tables?虽然我会问为什么将相同的值存储在两个表中?

When I look in http://dev.mysql.com/doc/refman/5.0/en/update.html , it looks like update...from is not allowed.当我查看http://dev.mysql.com/doc/refman/5.0/en/update.html时,似乎不允许更新...from

update tb_data_iae,tb_dialecte 
set tb_data_iae.nb_champs=tb_dialecte.nbchamps 
where nb_dialecte.id_dialecte = tb_data_iae.id_dialecte;

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

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