MySql - What happens when I update with 'and'

I ran ...

update TABLE set COLUMN1='XXX' and COLUMN2='YYY' where ID=9999; 
 Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 

Correct request:

 update TABLE set COLUMN1='XXX' , COLUMN2='YYY' where ID=9999; 

Why did MYSQL not give any errors?

+7
mysql
source share
1 answer

I just checked it, and it looks like MySQL refers to

'XXX' and COLUMN2 = 'YYY'

as an expression. Therefore, it compares the values โ€‹โ€‹of COLUMN2 and "YYY", gets a logical result and executes "XXX". And this is the result, so you probably get 0 in COLUMN1 at the end, since "XXX" is not DOUBLE / INTEGER / BOOLEAN. COLUMN2 will remain unchanged.

Thus, this request is not erroneous, it just does not match what was expected.

+2
source share

All Articles