Possible is, but syntax is terrible and I would not even recommend it:
UPDATE usuarios SET nome = (
CASE id WHEN 1 THEN 'Matheus Silva'
WHEN 2 THEN 'Lucas Silva'
END)
WHERE
id IN (1,2);
Imagine managing this type of query
.
Ideally, make querys
separated by ;
like @Hoppy replied.
$query = "
UPDATE usuarios SET nome='Matheus Silva' WHERE id=1;
UPDATE usuarios SET nome='Lucas Silva' WHERE id=2;
";
$mysqli->multi_query($query);
OBS
MySql has a specific option for this type of execution, which is multi_query
, that allows the execution of several querys
in the same string
, if the traditional query
is used only the first will be executed.
@Bacco Tip
Or send two processes to the bank.
$query = "UPDATE usuarios SET nome='Matheus Silva' WHERE id=1;"
$this->execute($query);
$query = "UPDATE usuarios SET nome='Lucas Silva' WHERE id=2;";
$this->execute($query);