Bug #65307 | Problem with order by and limit offset | ||
---|---|---|---|
Submitted: | 14 May 2012 4:02 | Modified: | 14 May 2012 13:20 |
Reporter: | Michelle Sollicito | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 5.5 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[14 May 2012 4:02]
Michelle Sollicito
[14 May 2012 6:19]
Valeriy Kravchuk
For me everything works: mysql> select user from mysql.user order by user; +------+ | user | +------+ | root | | root | | ue | +------+ 3 rows in set (0.03 sec) mysql> select user from mysql.user order by user limit 1; +------+ | user | +------+ | root | +------+ 1 row in set (0.01 sec) mysql> select user from mysql.user order by user limit 1 offset 1; +------+ | user | +------+ | root | +------+ 1 row in set (0.00 sec) mysql> select user from mysql.user order by 1 limit 1 offset 1; +------+ | user | +------+ | root | +------+ 1 row in set (0.00 sec) mysql> select version(); +------------+ | version() | +------------+ | 5.5.23-log | +------------+ 1 row in set (0.00 sec) So, please, provide complete test case, with CREATE TABLE and exact SELECT you try to use.
[14 May 2012 11:48]
Michelle Sollicito
It seems it is when there is a union in the query only e.g select a,b,c from table1 where a>10 union select a,b,c from table1 where a<3 order by a limit 10 offset 10;
[14 May 2012 13:20]
Valeriy Kravchuk
Then the following manual page applies, http://dev.mysql.com/doc/refman/5.5/en/union.html: "To use an ORDER BY or LIMIT clause to sort or limit the entire UNION result, parenthesize the individual SELECT statements and place the ORDER BY or LIMIT after the last one." Look: mysql> select user from mysql.user union select 'a' from dual; +------+ | user | +------+ | root | | | | u1 | | a | +------+ 4 rows in set (0.46 sec) mysql> select user from mysql.user union select 'a' from dual order by 1; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by 1' at line 1 mysql> select user from mysql.user union select 'a' from dual order by user; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by user' at line 1 But: mysql> (select user from mysql.user) union (select 'a' from dual) order by user; +------+ | user | +------+ | | | a | | root | | u1 | +------+ 4 rows in set (0.61 sec) mysql> (select user from mysql.user) union (select 'a' from dual) order by user limit 1; +------+ | user | +------+ | | +------+ 1 row in set (0.00 sec) mysql> (select user from mysql.user) union (select 'a' from dual) order by user limit 1 offset 2; +------+ | user | +------+ | root | +------+ 1 row in set (0.00 sec) This is not a bug.