I was surprised that this is not a syntax error:
UPDATE mytable
SET deleted = 1
AND name = 'Cindy'
It doesn’t affect the result of the command, is there any use of adding an AND
after a SET
? Or mysqsl will just ignore it?
I was surprised that this is not a syntax error:
UPDATE mytable
SET deleted = 1
AND name = 'Cindy'
It doesn’t affect the result of the command, is there any use of adding an AND
after a SET
? Or mysqsl will just ignore it?
2
Answers
Because the expression:
is a Boolean expression that evaluates to
0
forFalse
or1
forTrue
and the value of this expression will be assigned to the column
deleted
, like:The statement takes into account the operators precedence. And the query acts as
I.e. firstly the condition
name = 'Cindy'
is tested producing TRUE (1), FALSE (0) or NULL.Then the expression
1 AND {result}
is evaluated.And finally the result of this expression evaluation is assigned into
deleted
column.DEMO fiddle
If you receive the same result like for
then
name
column value is equal to'Cindy'
using current collation.