MySQL selects text after last slash

I have a mysql column that contains a VARCHAR that looks like this: folder1/folder2/<Entity>
For instance:

folder1/folder2/Apple
folder1/folder2/Microsoft
Since I would like to search in the entity field, I would like to add a column that contains only entity (and the query for $ searchTerm%). How can I select this last part after the last / directly in MySQL? I would like this column to just hold Apple and Microsoft in this example.

+6
source share
1 answer

The easiest way is to use substring_index() :

 select substring_index(mysql_column, '/', -1) 
+10
source

Source: https://habr.com/ru/post/973607/


All Articles