Mysql – Sorting ranking by trigger

MySQLsortingtrigger

I create a game in which players will gain levels. The basic information is in the table "char" (nickname, lvl, exp, money …).

I want to make a ranking that will be updated on a regular basis and works in real time. I think it makes no sense to perform the "ORDER BY lvl" operation on the "char" table every time someone enters the "Ranking" tab on the site.

My plan is this:

1) Make an additional table: "ranking" in which the data will be physically sorted.

2) Create a trigger that will update the ranking every time someone reaches a new level or someone creates a new character.
Does it make sense and is more efficient? If so, how can I do it? If not, how else to do it?

Best Answer

There is no such thing as "physical order" in the relational databases. Sometimes queries can produce the ordered results but that should be considered as "ordered by coincidence". There is absolutely no guarantee that you get the same ordered result each time.

If you need the ordered result the ORDER BY clause is a must.