MySQL ordering on CUSTOM field

There might be situation where you don’t need traditional sorting ordering. One might need to sort records in such a way that particular group of data will appear on the top. I was just looking for such functionality and bumped in to already built in functionality MySQL has: ORDER BY FIELD. Here is table and data dump.

Default Ordering
Here is the default ordering , the default order will be the order in which you have added enum values. The image shows the query i used for this, its just simple order by clause.

Now we will see two more image that will demonstartes you the ORDER by cluase.
Image 1 –
Image 2 –

The images are self explanatory enough to explain whats happening. Hope this helps.


Add a Comment

Your email address will not be published. Required fields are marked *