Skip to content

=

Operator Description

The = operator is used to assign values ​​in the following cases:

  • In the SET statement, = is regarded as an assignment operator, that is, the user variable to the left of the operator = takes the value to its right. The value to the right can be a text value, another variable that stores the value, or any legal expression that produces a scalar value, or it can also include the result of the query (provided that the value is a scalar value). Multiple assignments can be performed in the same SET statement.

  • In the SET clause of the UPDATE statement, = also acts as an assignment operator. You can make multiple assignments in the same SET clause of a UPDATE statement.

  • In other cases, = is used as the comparison operator.

Grammar Structure

> SELECT column1, column2, ...
FROM table_name
WHERE columnN = value1;

Example

create table t1 (a bigint(3), b bigint(5) primary key);
insert into t1 VALUES (1,1),(1,2);
update t1 set a=2 where a=1 limit 1;

mysql> select * from t1;
+------+------+
| a | b |
+------+------+
| 2 | 1 |
| 1 | 2 |
+------+------+
2 rows in set (0.00 sec)