Tag Archives: SQL

group of people choosing books

🐬 MySQL Order By Priority

Today I have been faced on situation where I need to display a list of users ordered by their name and their level. My table looks like below

idfirst_namelast_naelevel
1MuhammadSalahplayer
2JokoToleadmin
3CristioanoRonaldoplayer
4ZlatanIbrahimovicplayer
5JoseMourinhocoach
6MesutOzilplayer
7PepGuardiolacoach
8EdenHazardplayer
9PetrCechassistant manager
example table

My task is to show the table sorted by name, but give a priority order as: admin, coach, assistant manager, player.

You know we just can not order by level column since the result will sorted alphabetically.

Continue reading