I have a MySQL column that holds a VARCHAR
that looks like this:
folder1/folder2/<Entity>
For example:
folder1/folder2/Apple
folder1/folder2/Microsoft
Because I would like to perform a search on the entity field, I would like to add a column that just contains entity
(and the query for $searchTerm%
). How can I select that last part after the last /
directly in MySQL?
I would like that column to just hold Apple
and Microsoft
from the example.
SUBSTRING() function in MySQL function in MySQL is used to derive substring from any given string . It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.
People uses `` to surround field names and use '' to surround values. Is that true? Or the major reason to do so is because then we can put the code in a text file and import into the database. thank you. mysql.
We can use the ORDER BY statement and LIMT clause to extract the last data. The basic idea is to sort the sort the table in descending order and then we will limit the number of rows to 1. In this way, we will get the output as the last row of the table.
The easiest way is to use substring_index()
:
select substring_index(mysql_column, '/', -1)
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