Re: querying a database to sort ascending but list non null results first

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, April 25, 2007 12:54 pm, Tasneem Qadeer wrote:
> I hope you will take some time from your busy day to answer my
> question.

It's actually more of an SQL question, really....

However, getting the NULL results to be before/after the non-NULL
results is fairly easy:

select field1, field2, field3, remarks is null as prime
from whatever
order by remarks is null desc, field1, field2


By explicitly controlling the ORDER BY using the IS NULL operator, you
can choose where to put all the NULL results.

the "remarks is null as prime" bit gives you a calculated field
"prime" which tells you if they paid or not.

You can then test that in your PHP script and do whatever is
appropriate with colors or text output or dancing girls.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux