Query Output:
>
SELECT
@foo := 1,
@foo,
(SELECT @foo),
(SELECT foo FROM (SELECT @foo AS foo) subselect)
+ -------------- + --------- + ------------------ + ----------------------------------------------------- +
| @foo := 1 | @foo | (SELECT @foo) | (SELECT foo FROM (SELECT @foo AS foo) subselect) |
+ -------------- + --------- + ------------------ + ----------------------------------------------------- +
| 1 | 1 | 1 | 0 |
+ -------------- + --------- + ------------------ + ----------------------------------------------------- +
1 rows
Well... I just want to know why fourth column value is 0 instead 1.
解决方案
Because this FROM (SELECT @foo AS foo) is evaluated before this @foo := 1. Basically anything in FROM will be evaluated before your SELECT.
It actually should be null but Im guessing you've assigned your session variable a value of zero somewhere else.