HighDots Forums  

Slighty OT - ORDER BY query

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Slighty OT - ORDER BY query in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dorian Griffiths
 
Posts: n/a

Default Slighty OT - ORDER BY query - 06-01-2004 , 07:11 AM






Hi there

I have a new SQL statement that has the following piece of code in it:

ORDER BY ENHANCED, rand(), NAME ASC

Basically the script will display all ENHANCED listings at the top of the
output and then under that all the NAME listings. I want the ENHANCED
listings to be random but the name listings to be in alphabetical order. The
above piece of sql puts the enhanced random at the top and the names
randomised at the bottom.

My question is how do I make the NAMES part stay in alphabetical order? I
have rearranged the rand() in the statment to different locations but that
does not seem to work.

Any ideas would be much appreciated.

Cheers.

D.



Reply With Quote
  #2  
Old   
cmbergin
 
Posts: n/a

Default Re: Slighty OT - ORDER BY query - 06-01-2004 , 10:59 AM






Need a little more info. But you said you wanted to display all ENHANCED
listings at the top of the page in random order, then all NAME listings in
alphabetical order. This leads me to believe ENHANCED is some sort of boolean
field.

Try
ORDER BY CASE WHEN ENHANCED=1 THEN rand() ELSE NAME END

This assumes ENHANCED is an integer or bit field. You may have to change the
condition.
But basically, if a record is ENHANCED, then it's ordered by a random number.
If it's not, it's ordered by its name. This will only work if a name will
never start with a digit, e.g., if a one of the records has the name "5-Iron",
then it will probably show up somewhere within the ENHANCED listings.

Hope this can get you started.


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.