从你的另一个问题我知道你的意思是在用例中
SELECT variable = column FROM table;
来吧,亲眼看看……
CREATE TABLE foo (id int);
INSERT INTO foo VALUES (1), (2), (3);
SET @asdf = 2;
SET @asdf := 2; /*those are the same*/
/*As SET is always an assignment operation, it doesn't matter here if you write it with := or with =*/
SELECT id, @asdf, @asdf = id FROM foo;
回报
+------+-------+------------+
| id | @asdf | @asdf = id |
+------+-------+------------+
| 1 | 2 | 0 |
| 2 | 2 | 1 |
| 3 | 2 | 0 |
+------+-------+------------+
在结果中,最后一列中的0等于false,1等于true.
SELECT @asdf := id FROM foo;
回报
+-------------+
| @asdf := id |
+-------------+
| 1 |
| 2 |
| 3 |
+-------------+
因为id的值被赋给变量@asdf
如果你现在发出一个
SELECT @asdf;
它返回
+-------+
| @asdf |
+-------+
| 3 |
+-------+
因为最后选择了包含3的行.
SELECT @asdf := id FROM foo ORDER BY id DESC;
回报
+-------------+
| @asdf := id |
+-------------+
| 3 |
| 2 |
| 1 |
+-------------+
现在
SELECT @asdf;
回报
+-------+
| @asdf |
+-------+
| 1 |
+-------+
差异很明显了吗?