[Solved] Select Order by specific values
Posted: Tue Dec 12, 2006 4:22 am
Hello,
This one has been puzzling me for some time... If you have a table where 'type' column could be 'f','m','t' is there a way to use something like (this doesn't work...)
I know I could have a separate table of sort_order to join to but I was looking for a more generic way . Another example, in this one we have a load of data in regards to distance...
Again the SQL doesn't work but hopefully it shows what I am trying to accomplish. In this case a separate table for sort_order isn't really viable as each user needs a different order, possibly several. As a side note, although I use Postgres I am not after only Postgres solutions.
This one has been puzzling me for some time... If you have a table where 'type' column could be 'f','m','t' is there a way to use something like (this doesn't work...)
Code: Select all
SELECT * FROM contacts WHERE cust_id=66 ORDER BY type ('t','f','m');Code: Select all
$_SESSION['locs']=array('loc1'=>distance,'loc2'=>distance);
asort($_SESSION['locs'];
$locs=implode(',',array_keys($_SESSION['locs']));
$sql="SELECT * FROM table WHERE location IN ({$locs}) ORDER BY ({$locs});