View Full Version : Looking for suggestions on method to order records.

02-26-2007, 09:50 PM
I'm working on a Photo Gallery and currently working on a way order The photos. I've set up the following fields: Title, Description, photo_url, display_order. What I'm doing is using the display order to set the order the photos are displayed

Now here's the problem I'm running into. I have a gallery that has a bunch of photos and I only care about setting the order on say 5 of the photos and don't care about the order of the rest so I enter 1-5 in display_order on those 5 records. When I issue the SQL search "order by display_order" all the records with null in the display_order are comming up first, rather then the 5 records with the 1-5 in display_order.

Any suggestions on how to get those 5 records to display first and in order?

02-26-2007, 10:05 PM
hmm...postgres sticks nulls at the end...

you could try:
order by (display_order IS NULL), display_order

02-26-2007, 10:50 PM
Thanks GJay,

"order by (display_order IS NULL), display_order" did the trick, have never seen an order by done like that.