MySQL Substring Captures all but the last three characters

Basically, I'm trying to find the inverse of this command: substring(term, -3) .

+4
source share
3 answers

Try the following:

 SELECT SubStr(myColumn, 1, LENGTH(myColumn) - 3) FROM MyTable 

or

 SELECT LEFT(myColumn, LENGTH(myColumn) - 3) FROM MyTable 
+11
source

This should do it: SELECT SUBSTRING(term FROM 1 FOR LENGTH(term)-3)

+2
source

If you need to match it by comparison, you can use

 WHERE somefield LIKE 'term___' 
-1
source

All Articles