Топ-100
top of page
CerebroSQL

ASSIGN-VALUE

Database: MySQL

68747470733a2f2f7374796c65732e7265646469746d656469612e636f6d2f74355f32716d366b2f7374796c65

Topic

Syntax:
:=

Assignment operator. Causes the user variable on the left hand side of
the operator to take on the value to its right. The value on the right
hand side may be a literal value, another variable storing a value, or
any legal expression that yields a scalar value, including the result
of a query (provided that this value is a scalar value). You can
perform multiple assignments in the same SET statement. You can perform
multiple assignments in the same statement.

Unlike =, the := operator is never interpreted as a comparison
operator. This means you can use := in any valid SQL statement (not
just in SET statements) to assign a value to a variable.

Example

mysql> SELECT @var1, @var2;
-> NULL, NULL
mysql> SELECT @var1 := 1, @var2;
-> 1, NULL
mysql> SELECT @var1, @var2;
-> 1, NULL
mysql> SELECT @var1, @var2 := @var1;
-> 1, 1
mysql> SELECT @var1, @var2;
-> 1, 1

mysql> SELECT @var1:=COUNT(*) FROM t1;
-> 4
mysql> SELECT @var1;
-> 4

bottom of page