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 –
default-ordering
Image 2 –
custom-ordering

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

Tags:

Add a Comment

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