Mysql – How to sort MySQL query records from big to small numbers

mysql

I'm trying to sort my records from big to small numbers, here are my example records:

id   name   view   like
1   name1    5      1
2   name2    2      4
3   name3    41     3
4   name4    6      31
5   name5    1      2

For example, I want the order the records like this (i.e. ordered by the field named like):

id   name   view   like
4   name4    6      31
2   name2    2      4
3   name3    41     3
5   name5    1      2
1   name1    5      1

I tried this query…

SELECT * FROM tablename ORDER BY like DESC

…but the query result is like this now:

id   name   view   like
2   name2    2      4
3   name3    41     3
4   name4    6      31
5   name5    1      2
1   name1    5      1

So, what is the correct query for what I want?

Best Solution

like is a reserved word in mysql

You can escape it by using backticks; ``

SELECT * FROM `tablename` ORDER BY `like` DESC