Unable to update from selected

Hi, I have two tables:

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 am trying to update the field of the first table "nb_champs" from the same field that appears in the second table

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 the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use next to 'tb_dialecte, where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte' on line 1

I don’t know how to debug this, since I try a lot of queries, but nobody works, and the error message is almost the same every time it is higher ...

thanks for the help!

+3
source share
2 answers
update tb_data_iae set nb_champs=(SELECT tb_dialecte.nbchamps 
from tb_dialecte 
where tb_dialecte.id_dialecte = tb_data_iae.id_dialecte);

Although I would ask, why store the same values ​​in two tables?

+2

http://dev.mysql.com/doc/refman/5.0/en/update.html, ... .

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;
+1

All Articles