user1794019
user1794019

Reputation: 57

Update column with select

hello I would like to set a table column I tried with the update query but I have syntax error

  $cmts="UPDATE stat_alert INNER  JOIN cell_cmt  ON stat_alert.cell = cell_cmt.cell SET stat_alert.`cmts` = cell_cmt.`Cmts`";
$cmt= mysql_query($cmts)OR DIE("Erreur sur la requete");

I have erreur sur la requete who can help me

Upvotes: 0

Views: 104

Answers (3)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

Try this code: you have en error of syntax because from gone before the set. Set have to be after the inner join

UPDATE stat_alert a 
INNER  JOIN cell_cmt b ON a.cell = b.cell
SET a.`cmts` = b.`Cmts`

Upvotes: 2

John Woo
John Woo

Reputation: 263693

You are using version of UPDATE with JOIN in MSSQL, In MYSQL, it should be like this, (FROM keyword shouldn't be specified)

UPDATE stat_alert a 
       INNER  JOIN cell_cmt b
          ON a.cell = b.cell
SET a.`cmts` = b.`Cmts`

Upvotes: 1

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79909

Here is the right syntax for UPDATE with JOIN:

UPDATE stat_alert
INNER  JOIN cell_cmt ON stat_alert.cell = cell_cmt.cell
SET 
  stat_alert.`cmts` = cell_cmt.`Cmts`

The mysql UPDATE dictates that the table references stat_alert INNER JOIN cell_cmt ON stat_alert.cell = cell_cmt.cell comes after the UPDATE clause directly. Thats what you was missing.

Upvotes: 1

Related Questions