Description:
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
`c1` int(11) NOT NULL auto_increment,
`c2` varchar(16) NOT NULL default '',
`c3` int(11) NOT NULL default '0',
PRIMARY KEY (`c1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `t1` VALUES (43,'0',0),(57,'0',0),(97,'0',0),(119,'0',0),(124,'0',0),(125,'0',0),(144,'0',0),(159,'0',1),(175,'0',0),(188,'0',3),(226,'0',0),(280,'0',0),(359,'0',0),(366,'0',0),(395,'617868',60408),(462,'14',2),(463,'0',0),(464,'0',82),(465,'0',0),(466,'0',0),(467,'0',5);
SELECT c1, c2 AS 'c 2', c3 as 'c 3' from t1 GROUP BY c1 ORDER BY 'c 2' DESC, c3 ASC;
Slightly possible that these are related patches.
(Bug#24653)(Bug#24562)
Working statement in 4.1.20;
mysql> SELECT c1, c2 AS 'c 2', c3 from t1 GROUP BY c1 ORDER BY 'c 2' DESC, c3 ASC;
+-----+--------+-------+
| c1 | c 2 | c3 |
+-----+--------+-------+
| 395 | 617868 | 60408 |
| 462 | 14 | 2 |
| 124 | 0 | 0 |
| 359 | 0 | 0 |
| 125 | 0 | 0 |
| 366 | 0 | 0 |
| 144 | 0 | 0 |
| 43 | 0 | 0 |
| 175 | 0 | 0 |
| 463 | 0 | 0 |
| 57 | 0 | 0 |
| 97 | 0 | 0 |
| 226 | 0 | 0 |
| 465 | 0 | 0 |
| 119 | 0 | 0 |
| 280 | 0 | 0 |
| 466 | 0 | 0 |
| 159 | 0 | 1 |
| 188 | 0 | 3 |
| 467 | 0 | 5 |
| 464 | 0 | 82 |
+-----+--------+-------+
21 rows in set (0.00 sec)
mysql> select VERSION();
+----------------+
| VERSION() |
+----------------+
| 4.1.20-max-log |
+----------------+
1 row in set (0.00 sec)
No longer working in 4.1.23 (same behavior in latest 5.0)
mysql> select VERSION();
+--------------------+
| VERSION() |
+--------------------+
| 4.1.23-pro-gpl-log |
+--------------------+
1 row in set (0.00 sec)
mysql> SELECT c1, c2 AS 'c 2', c3 from t1 GROUP BY c1 ORDER BY 'c 2' DESC, c3 ASC;
+-----+--------+-------+
| c1 | c 2 | c3 |
+-----+--------+-------+
| 43 | 0 | 0 |
| 466 | 0 | 0 |
| 465 | 0 | 0 |
| 463 | 0 | 0 |
| 366 | 0 | 0 |
| 359 | 0 | 0 |
| 280 | 0 | 0 |
| 226 | 0 | 0 |
| 175 | 0 | 0 |
| 144 | 0 | 0 |
| 125 | 0 | 0 |
| 124 | 0 | 0 |
| 57 | 0 | 0 |
| 97 | 0 | 0 |
| 119 | 0 | 0 |
| 159 | 0 | 1 |
| 462 | 14 | 2 |
| 188 | 0 | 3 |
| 467 | 0 | 5 |
| 464 | 0 | 82 |
| 395 | 617868 | 60408 |
+-----+--------+-------+
21 rows in set (0.00 sec)
=====
Similar sort of handling;
mysql> select i, b as 'test' from a order by 4;
ERROR 1054 (42S22): Unknown column '4' in 'order clause'
mysql> select i, b as 'test' from a order by '4';
+------+-------+
| i | test |
+------+-------+
| 1 | test |
| 2 | zed |
| 3 | alpha |
+------+-------+
3 rows in set (0.01 sec)
How to repeat:
As above queries.
Possible undocumented behavior change, as 5.0 presents the same 4.1.23 results.