Referencing: SET user defined variable in mysql return null?

I tested the following code:

SET @rank=0;
SELECT *, @rank:=@rank+1 AS rank FROM points

For points in PhpMyAdmin it returns:

id | user_id | points | rank
-----------------------------
2  | 133845  | 220    | 1
4  | 134084  | 220    | 2
5  |      1  | 150    | 3
7  | 134086  | 145    | 4


HOWEVER in SQLYog all the ranks return as "NULL" I checked my configs and set timeout to 28800 seconds and turned off compression protocol. MySQL seems to stay on one single session but SQLYog seems to be using two connections for this query. How can I set the application to one single connection so I don't lose the variable values?

有帮助吗?

解决方案

Multiple queries within one instance. They're being stacked in individual instances.

As Jan suggest "Execute all statements" command should do the trick.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top