hungrykoala hungrykoala - 4 months ago 7
MySQL Question

How to remove some texts from a field during a select query?

I have a field in my table that contains this value:

#3 text For string# 1
#4 Payment For Inv# 5


What I want to do here is to only display "1 and 5" after a select query, and the problem is that #n is not limited to a single digit only thus, I cannot use SUBSTRING.

Any ideas on how to proceed with this?

Answer

As 1 and 5 comes at last position of string so you get the last character of string as

SELECT SUBSTRING_INDEX(YOUR_COLUMN, ' ', -1) FROM YOUR_TABLE
Comments