Re: correct order by for logical output
some experimentation.
mysql> select * from words
-> ;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 2 | 1a |
| 3 | 2b |
| 4 | 2a |
| 5 | 2 |
| 6 | 1.1 |
| 7 | 1.1a |
| 8 | 1.2b |
| 9 | 1.2a |
| 10 | 1.2 |
+----+------+
10 rows in set (0.03 sec)
mysql> select * from words order by name;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 6 | 1.1 |
| 7 | 1.1a |
| 10 | 1.2 |
| 9 | 1.2a |
| 8 | 1.2b |
| 2 | 1a |
| 5 | 2 |
| 4 | 2a |
| 3 | 2b |
+----+------+
10 rows in set (0.02 sec)
mysql> select * from words order by left(name,2);
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 6 | 1.1 |
| 7 | 1.1a |
| 8 | 1.2b |
| 9 | 1.2a |
| 10 | 1.2 |
| 2 | 1a |
| 5 | 2 |
| 4 | 2a |
| 3 | 2b |
+----+------+
10 rows in set (0.02 sec)
mysql> select * from words order by left(name,3);
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 6 | 1.1 |
| 7 | 1.1a |
| 8 | 1.2b |
| 9 | 1.2a |
| 10 | 1.2 |
| 2 | 1a |
| 5 | 2 |
| 4 | 2a |
| 3 | 2b |
+----+------+
10 rows in set (0.02 sec)
mysql> select * from words order by left(name,4);
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 6 | 1.1 |
| 7 | 1.1a |
| 10 | 1.2 |
| 9 | 1.2a |
| 8 | 1.2b |
| 2 | 1a |
| 5 | 2 |
| 4 | 2a |
| 3 | 2b |
+----+------+
10 rows in set (0.03 sec)
mysql> select * from words order by left(name,0);
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 2 | 1a |
| 3 | 2b |
| 4 | 2a |
| 5 | 2 |
| 6 | 1.1 |
| 7 | 1.1a |
| 8 | 1.2b |
| 9 | 1.2a |
| 10 | 1.2 |
+----+------+
10 rows in set (0.02 sec)
mysql> select * from words order by name;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 6 | 1.1 |
| 7 | 1.1a |
| 10 | 1.2 |
| 9 | 1.2a |
| 8 | 1.2b |
| 2 | 1a |
| 5 | 2 |
| 4 | 2a |
| 3 | 2b |
+----+------+
10 rows in set (0.10 sec)
Subject
Written By
Posted
Re: correct order by for logical output
July 13, 2005 03:12AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.