How to retrieve the last 4 characters from a mysql database field?

Toni Michel Caubet picture Toni Michel Caubet · Mar 29, 2011 · Viewed 36.6k times · Source

In order to be able to simulate substr from PHP and mysql, I want to do something like

select * from table where last_four_chars(field) = '.png'

Answer

Frank Farmer picture Frank Farmer · Mar 29, 2011

The docs have an example directly relevant to this.

select * from table where SUBSTRING(field, -4) = '.png'