开发者

impossible to update from a select

开发者 https://www.devze.com 2023-03-08 20:23 出处:网络
Hi i ve got two tables like this: mysql> describe tb_data_iae; +--------------------+--------------+------+-----+---------+----------------+

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

my开发者_运维百科sql> 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; 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

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.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消