Reputation: 3391
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.
Upvotes: 12
Views: 5944
Reputation: 1269713
The easiest way is to use substring_index()
:
select substring_index(mysql_column, '/', -1)
Upvotes: 25