0

LINK: https://dev.mysql.com/doc/refman/5.7/en/user-variables.html

I was reading mysql documentation and I got really confused about that general rule!

Documentation:

As a general rule, OTHER THAN IN SET statements, you should never assign a value to a user variable and read the value within the same statement.

Ok, so does it means that I can use SET statement to assign AND READ a user variable? right? BUT when I try it...

SET @a:=1, @b:=@a+1;
SELECT @a,@b; # @a = 1, @b = NULL

Looks like the SET statement have the same problem of any other statement for assign and read user variables in the same statement.

SET @a:=1;
SET @b:=@a+1;
SELECT @a,@b; # @a=1 , @b=2

So, what am I missing here?

1 Answer 1

1

I think the documentation is simply wrong. As you've shown, there's not really any difference between SET and SELECT in this regard.

Sign up to request clarification or add additional context in comments.

3 Comments

and this is not ok either: SET @a:=1, @b:=@a+1; so what exacly is the difference between a SET statement and SELECT? that part: "OTHER THAN IN SET statements" makes no sense
I know, that's in your question.
Oh okay. Thanks for replying. :P

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.