SUBSTRING_INDEX() function in MySQL — with examples.
I recently used the MySQL SUBSTRING_INDEX(), function for a requirement in a PHP/MySQL reporting dashboard I am developing, and thought to write about SUBSTRING_INDEX()
general usage. Although this post has arbitrary examples, I’m sure you can find a use for this function in specific cases. Continue reading and see basic queries including SUBSTRING_INDEX
in the SELECT
clause…
OS, Software, and DB used:
- OpenSuse Leap 15.1
- MySQL 8.0.19
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
SUBSTRING_INDEX()
accepts 3 arguments:
- A string to search.
- A delimiter to search on.
- A number of occurrences of the specified delimiter. In other words, which occurrence of the delimiter to split on should multiple be present in the string to search.
I will use a simple table, ‘file_names’ for the examples throughout the post:
MySQL localhost:33060+ ssl learning SQL > DESC file_names;
+ — — — — — — -+ — — — + — — — + — — -+ — — — — -+…