0

I need order by Numbers from end of title but need as UNSIGNED result, i try to get last 5 digit from title table and sort but not giving natural result

title table

title1 (2015)
something (1999)
title1 (1994
title1 (2014)

My code

 ORDER BY RIGHT(title,5) DESC

Result is

something (1999)
title1 (1994)
title1 (2014)
title1 (2015)

How can i Order like this:

title1 (2015)
title1 (2014)
something (1999)
title1 (1994)

Now this code order like 1,10,101,2,20,201 but i need like this 1,2,10,20,101,201

Raj Mohammed
  • 173
  • 1
  • 3
  • 10

3 Answers3

1

Because you substring, it converts the data to text.

You need to convert it back to number (source):

order by substring(title,-5,4)*1 desc;
Community
  • 1
  • 1
NotJustin
  • 529
  • 6
  • 20
0

You need ORDER BY ASC and not DESC.

ORDER BY RIGHT(title,5) ASC

Learn more here.

Andrea php
  • 63
  • 2
  • 8
0

What if you try like this. See a DEMO HERE

select col1 from table1
order by replace(right(col1,5), ')','') desc;
Rahul
  • 76,197
  • 13
  • 71
  • 125