Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
None
-
None
-
None
-
Debian squeeze (x64)
Description
I need to insert data from a SELECT query with an ORDER BY and a SQL variable (like @a). The final query look like this :
SET @var=0; |
INSERT INTO rank (position,petId,userId) SELECT (@var:=@var+1), id, userId FROM pet ORDER BY p.experience DESC ON DUPLICATE KEY UPDATE oldPosition=position, position=VALUES(position); |
Result look like :
| position | petId | userId |
|---|---|---|
| 1 | 15 | 6 |
| 2 | 24 | 12 |
| 3 | 7 | 4 |
| ... |
It work but when I want to add a JOIN in this query, the ordering does not work (use natural ordering) :
SET @var=0; |
INSERT INTO rank (position,petId,userId) SELECT (@var:=@var+1), p.id, p.userId, FROM pet AS p JOIN user AS u ON p.userId = u.id AND u.lastConnection >= ADDDATE(NOW(), INTERVAL -1 MONTH) ORDER BY p.experience DESC ON DUPLICATE KEY UPDATE oldPosition=position, position=VALUES(position); |
| position | petId | userId |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | 3 | 2 |
| ... |
I already test it with an INNER JOIN or a subquery but it return the same result.
Note : This request (with JOIN) work fine on MYSQL.
Note2 : We use MariaDB 5.5.32 (I don't find this version on your "Affects [...]" list).
Note3 : We are using InnoDB engine.