suttercain Posted November 17, 2009 Share Posted November 17, 2009 Hi everyone, I have a column with the following records: UCLA YALE HARVARD USC I want USC to always appear first, or outputted at the top of the list. If I ORDER BY it will alphabetize the results and I won't get the desired result. I looked into using CASE but couldn't get it. Does anyone know a way to have a specified result appear at the top of the list all the time? Thanks! Link to comment https://forums.phpfreaks.com/topic/181919-custom-sort-order-or-default-results-first/ Share on other sites More sharing options...
kickstart Posted November 18, 2009 Share Posted November 18, 2009 Hi You could use case. However I assume that these records can appear multiple times (eg, a list of students with the facility that they are at) If so it might be best to have another table listing the sort order for those items. Then JOIN your current table to that new table to get the sort order. All the best Keith Link to comment https://forums.phpfreaks.com/topic/181919-custom-sort-order-or-default-results-first/#findComment-959914 Share on other sites More sharing options...
JustLikeIcarus Posted November 18, 2009 Share Posted November 18, 2009 As kickstart mentioned your 2 best options are having a table specifying the order or another column in that table specifying the order. These would be best when it comes to optimization however you could also do ORDER BY FIELD(school_name, 'USC') desc, school_name school_name would be the name of your column containing... well the school names Link to comment https://forums.phpfreaks.com/topic/181919-custom-sort-order-or-default-results-first/#findComment-960007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.