Natan Coats Natan Coats - 6 months ago 7
MySQL Question

what is wrong with this query? I am trying to update a column value based on the value of a column in a second table

So I am trying to update the value of column

Proveedor_Logo
in table
Natan_Procesos
with the value of column
Proveedor_Logo
in table
Natan_Proveedor
where the row in table
Natan_Procesos
has a column named
Producto_Prioridad
and has a value of 1:

$logo = $db->query( "UPDATE `quehago`.`Natan_Procesos`
SET `Proveedor_Logo` = `Proveedor_Logo`
WHERE `Natan_Procesos`.`Producto_Prioridad` =
( SELECT `Natan_Procesos`.`Producto_Prioridad` =1 )");


No error appears but no value is passed either. What am I missing?

UPDATE from replies:

so I changed it to: (with no update still)

$logo = $db->query( "UPDATE `quehago`.`Natan_Procesos`
SET `Proveedor_Logo` = `Proveedor_Logo`
WHERE `Natan_Procesos`.`Producto_Prioridad` =
( SELECT * FROM `Natan_Procesos` WHERE `Producto_Prioridad` = 1)");


But I still think that there is something not right in as to where the values should be stored into. I need them to be stored into Table Natan_Procesos in column Proveedor_Logo. or where I am getting the value from?

SECOND UPDATE:

both tables have a column named Proveedor_ID that could be a second condition to match. so it would read something like this: Update column Proveedor_Logo in table Natan_Procesos where value in column Producto_Prioridad = 1 FROM column Proveedor_Logo in table Natan_Proveedor where both Natan_Proveedor and Natan_Procesos have an identical value in column Proveedor_ID

Answer

Try:

"UPDATE  `quehago`.`Natan_Procesos` 
 SET  `Proveedor_Logo` =  `Proveedor_Logo` 
 WHERE  `Natan_Procesos`.`Producto_Prioridad` = 
   ( SELECT `Natan_Procesos`.`Producto_Prioridad` FROM `Natan_Procesos` WHERE `Producto_Prioridad` = 1 )"

Should it be something like this?:

`"UPDATE  `quehago`.`Natan_Procesos` 
  SET  `Natan_Procesos`.`Proveedor_Logo` =  ( SELECT   `Natan_Proveedor`.`Proveedor_Logo` FROM `Natan_Proveedor` WHERE ?? = ?? )
  WHERE  `Natan_Procesos`.`Producto_Prioridad` = 1"`

Try this:

 UPDATE  `quehago`.`Natan_Procesos` 
 INNER JOIN `Natan_Proveedor` ON
    `Natan_Procesos`.`Proveedor_ID` = `Natan_Proveedor`.`Proveedor_ID`
 SET  `Natan_Procesos`.`Proveedor_Logo` =  `Natan_Proveedor`.`Proveedor_Logo` 
 WHERE  `Natan_Procesos`.`Producto_Prioridad` = 1
Comments