0

enter image description here

https://www.w3schools.com/mysql/mysql_operators.asp

Came across this. I am studying MySQL as a beginner and I can't seem to find anything on the internet that works.

I can't even find them in https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html.

Could I have the simplest working syntax of how these compound operators work?

Thank you very much.


These are my attempts:

UPDATE tableName
SET intColumn += 5
WHERE id = 5;

UPDATE tableName
SET intColumn = ((intColumn) + 5)
WHERE id = 5;

UPDATE tableName
SET intColumn = ((SELECT intColumn FROM tableName WHERE id = 5) + 5)
WHERE id = 5;

-- works --
UPDATE tableName
SET intColumn = tableName.intColumn + 5
WHERE id = 5;
SELECT * FROM tableName;

@variables

SET @intVar = 0;
SELECT @intVar;
SET @intVar += 10;

-- works but += doesn't?
SET @intVar = @intVar + 50;
SELECT @intVar;
askein
  • 39
  • 4
  • 1
    I'm just guessing here but "intColumn" is actually the name of the table. The SET command however is for setting a variable so would be no table name for most of those queries. The last query only adds 5 to a variable, so only accidentally has enough correct syntax to operate. – Samuel Marchant Mar 18 '23 at 09:56
  • 1
    User defined variables https://dev.mysql.com/doc/refman/8.0/en/user-variables.html. – Samuel Marchant Mar 18 '23 at 10:29
  • 1
    MySQL does not know about these operators... https://dev.mysql.com/doc/refman/8.0/en/non-typed-operators.html w3schools obviously imagines them. – Akina Mar 18 '23 at 11:22
  • They don't exist? How about older versions of MySQL? – askein Mar 18 '23 at 12:03
  • 2
    @inheasks mysql never ever had these operators. w3schools is unfortunately known to be inaccurate.... – Shadow Mar 18 '23 at 12:20
  • 1
    Microsoft SQL Server has compound operators, but this is their own extension to standard SQL. Cf. https://learn.microsoft.com/en-us/sql/t-sql/language-elements/compound-operators-transact-sql?view=sql-server-ver16 MySQL and Microsoft SQL Server are different products, with distinct features. Whoever wrote that w3schools article was apparently confused by the fact that "MySQL" and "Microsoft" begin with the same syllable. – Bill Karwin Mar 18 '23 at 16:26

2 Answers2

2

Mysql does not have compound operators. For the complete list of operators in mysql see mysql manual

Shadow
  • 33,525
  • 10
  • 51
  • 64
0

You can try:

UPDATE tableName
SET intColumn = intColumn + 5
WHERE id = 5;
Lunar
  • 57
  • 7