I have seen many threads on how to sort using a specific order rather than using the default ASC or DESC options. However, I have a series of values in a column where I would like 1 particular value to always come at the top, one particular value that I would like to have always on the bottom and everything else can be sorted by ASC in between. Let me provide a generic example below. Imagine I have a column of information like the following.
Value1 | Value5 | Value3 | Value9 | Value8 | Value7 | Value5 | Value3 | Value6
NOTE: Please pretend, for the sake of argument, that this is one single column and not a row of information. It is simply easier for spacing on this forum to present it horizontally. Please imagine it’s a vertical list.
I would like Value5 to be at the top of the order and Value3 to be at the bottom. Such that the rows of information would be returned in the following order:
Value5 | Value5 | Value1 | Value6 | Value7 | Value8 | Value9 | Value3 | Value3
Notice that the 5’s came first, the 3’s came last, and everything else was returned in alphabetical order between those two values.
I’m using PHP, in case that has any bearing on the situation.
You need a conditional statement on the
ORDER BYclause of your query: