2

How do I write the following in MYSQL?

SELECT SUBSTRING(value - (1 TRAILING CHARACTER)) FROM table;

Basically substring(value, 2) trims the first letters. But I need to trim the last letters. I can't use substring(value, -4, 3) because I don't know the length of the value.

Here's another example: SELECT * FROM table WHERE SUBSTRING(value - (4 TRAILING CHARACTER)) in (SELECT SUBSTRING(value - (1 TRAILING CHARACTER)) FROM table);

Tim
  • 23
  • 1
  • 3

1 Answers1

5

E.g., to remove the last 2 characters from string value:

substring(value, 1, length(value) - 2)
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395