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'
You can select last characters with - This will be giving you all the lines but only with their last 4 characters.
It could be this using the SUBSTR function in MySQL: SELECT `name` FROM `students` WHERE `marks` > 75 ORDER BY SUBSTR(`name`, -3), ID ASC; SUBSTR(name, -3) will select the last three characters in the name column of the student table.
SQL Server RIGHT() Function The RIGHT() function extracts a number of characters from a string (starting from right).
The docs have an example directly relevant to this.
select * from table where SUBSTRING(field, -4) = '.png'
With RIGHT function :
SELECT RIGHT('abcdefg', 3); -- efg
You can achieve the same result with SUBSTRING :
SELECT SUBSTRING('abcdefg', -3); -- efg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With