For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > April 2004 > displaying empty strings last when using order by









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author displaying empty strings last when using order by
davidklonski

2004-04-24, 8:30 pm

Hello

I would like to be able to display the content of a table sorted
alphabetically (ascending) by 'name' (one of the columns)
with the following little twist:
all the rows which have an empty name column should be displayed last.
The rest of the rows should be displayed before them with regular
ascending alphabetical order.

I also have the requirement that I must use limit x,y on the query so
I will not extract the entire table.

how can I combine all these requirements into a single query?



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


denisb

2004-04-28, 1:46 pm

davidklonski <davidklonski@fastmail-dot-fm.no-spam.invalid> wrote:
> Hello


bonjour,

> I would like to be able to display the content of a table sorted
> alphabetically (ascending) by 'name' (one of the columns)
> with the following little twist:
> all the rows which have an empty name column should be displayed last.
> The rest of the rows should be displayed before them with regular
> ascending alphabetical order.
> I also have the requirement that I must use limit x,y on the query so
> I will not extract the entire table.
> how can I combine all these requirements into a single query?


SELECT (table.name = '') AS truc, table.name
FROM table
WHERE 1
ORDER BY truc, table.name ASC
LIMIT x , y

--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com