Get part of the string from a string in MySQL

We may occasionally need to search within a string for a certain text. Multiple built-in functions provided by MySQL made the task simple.

To extract a substring from a string, use the MID, SUBSTR, and SUBSTRING functions (starting at any position). All three of these functions perform similarly and give the same result.

Examples:
SELECT MID(“Big Data and SQL”, 5, 4) AS ExtractString;
SELECT SUBSTR(“Big Data and SQL”, 5, 4) AS ExtractString;
SELECT SUBSTRING(“Big Data and SQL”, 5, 4) AS ExtractString;

Since we specified the start location and length of the string to be extracted from that place, all of the aforementioned returns “Data” as the outcome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s