Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by predertimined list 1

Status
Not open for further replies.

LuKJared

Programmer
Feb 9, 2004
1
US
I have a table were each record has a unique ID. I also have a list of all the ID numbers in a specific order. The order may change each time the page(this is a coldfusion website)is loaded. Is there any way to order the records based on the list of unique ID's. For example, I may need the first record to be VehicleID=14, 2nd to be VehicleID=12, 3rd - VehicleID=2, 4th-VehicleID=7, etc...I already have this list created. What can I do to accomplish this?
 
Create a temporary table with the ID numbers in the desired order and join the two tables order by the temporary column.

Hope This Help
PH.
 
generate the ORDER BY list in coldfusion on the fly:

[tt]select foo, bar, qux
from yourtable
order
by case when VehicleID=14 then 0 else 1 end
, case when VehicleID=12 then 0 else 1 end
, case when VehicleID=2 then 0 else 1 end
, case when VehicleID=7 then 0 else 1 end[/tt]



rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top