Getting last 5 char of string with mysql query

user1253602 picture user1253602 · Apr 13, 2012 · Viewed 68.6k times · Source

I have to get last 5 numbers using mysql.

My values are like YOT-A78514,LOP-C4521 ...

I have to get only last five char . How can I do this in query?

Answer

user319198 picture user319198 · Apr 13, 2012

You can do this with RIGHT(str,len) function. Returns the rightmost len characters from the string str,

Like below:

SELECT RIGHT(columnname,5) as yourvalue FROM tablename