How to sort MySQL query records from big to small numbers -


i'm trying sort records big small numbers, here example records:

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

for example, want order records (i.e. ordered field named like):

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

i tried query...

select * tablename order desc 

...but query result now:

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

so, correct query want?

looks storing numerical value of like in string format; either char or varchar. result in alphabetical style ordering can see (imagine 1 a, 2 b, etc.. , order results words).

change datatype of column numerical format int , query should behave expected.

if cannot change datatype of column suggest casting in query:

select * tablename order cast(`like` unsigned) desc 

or

select * tablename order cast(`like` signed) desc 

if like can negative.

i find more readable , controlled +0, abhik beat me :)


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -