tags:

views:

33

answers:

3

I am displaying a list of categories in ASC order."OTHERS" is also one of the category. I need to display all categories in ASC ORDER and "OTHERS" in last .

This is done by using PHP and MYSQL.

TABLE STRUCTURE

tale name: categories

id categoryname

1  APPLE

2  BANANA

3  Strawberry

4  Other

5  grape

For example: the above is the table structure. From the above table i need to display all the categories in ASC Order and need to display "OTHER" at last. So the output should be exactly like below.

id categoryname

1  APPLE

2  BANANA

3  grape

4  Strawberry 

5  Other

Thanks n advance...

A: 
SELECT * FROM categories ORDER BY Column1 ASC, Column2 ASC, Column3 DESC
TeknoSeyfo
please view the question again seyfo. I explained it in breif
Fero
Hımm ok. I'm sorry :(
TeknoSeyfo
No need sorry Seyfo... Just FYI.
Fero
+1  A: 

You could try something like

SELECT  *
FROM    Categories
ORDER BY    CASE 
                WHEN Categorie = 'OTHERS' THEN 2 
                ELSE 1 
            END, 
            Categorie
astander
this is what i exactly need.. thanks a lot astander
Fero
I believe this will only sort 'others' to the end of the list, and not sort the categories.
Duncan
The order by clause has 2 sections, so try running it and see. It will sort asc by the 1/2 id and then by Category.
astander
will you please explain me the query astander.. I am new to CASE in mysql.. sorry for the inconvenience
Fero
@astander: Sorry, I misread the query, and didn't see the second part of the clause. Light blue on grey at the end of a long day I guess. Perhaps I just stopped reading when I saw the word `END` :)
Duncan
A: 
SELECT *
FROM categories
ORDER BY categories LIKE 'others' ASC, categories ASC
Duncan