Re: order by problem
On Sat, 12 Jan 2008 21:23:38 -0000 wrote Charles Polisher
<cpolish@nonesuch.com>:
>On 2008-01-12, Jannis <anne.bosscha@hccnet.nl> wrote:
>> In a mysql database is a field called 'number' which is actually
>> filled by numbers. In a query I want my results ordered by number so
>> the last clause in my query is ORDER BY 'number'. Numbers then are
>> given in an 'alphabetical'order: first 100 and later e.g. 83 etc. Is
>> it possible to get numbers like this in such a way that in a sequence
>> from 1 to 111 the 1 comes first and 111 last? Ordering by id or other
>> field is no option.
>> The number field is INT(3).
>> Thank you,
>> Onno
>
>Works for me. I think you are using 'apostrophes'
>where you intended `backticks`.
>
>mysql> create table foo (`number` int(3));
>Query OK, 0 rows affected (0.04 sec)
>
>mysql> insert into foo set `number` = 10;
>Query OK, 1 row affected (0.02 sec)
>
>mysql> insert into foo set `number` = 111;
>Query OK, 1 row affected (0.01 sec)
>
>mysql> insert into foo set `number` = 1;
>Query OK, 1 row affected (0.01 sec)
>
>mysql> SELECT * FROM foo;
>+--------+
>| number |
>+--------+
>| 10 |
>| 111 |
>| 1 |
>+--------+
>3 rows in set (0.00 sec)
>
>mysql> SELECT * FROM foo ORDER BY `number`;
>+--------+
>| number |
>+--------+
>| 1 |
>| 10 |
>| 111 |
>+--------+
>3 rows in set (0.00 sec)
>
Actually I used those `backticks`. Sorry about that. Still 2 comes
after 111.
|