Re: [PHP] querying a database to sort ascending but list non nullresults first

This is a discussion on Re: [PHP] querying a database to sort ascending but list non nullresults first within the PHP General forums, part of the PHP Programming Forums category; On Wed, April 25, 2007 12:54 pm, Tasneem Qadeer wrote: > I hope you will take some time from ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-25-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] querying a database to sort ascending but list non nullresults first

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?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0