Home > Database > Mysql Tutorial > How can I extract the substring after the third space in a MySQL string?

How can I extract the substring after the third space in a MySQL string?

Patricia Arquette
Release: 2024-10-24 23:33:31
Original
807 people have browsed it

How can I extract the substring after the third space in a MySQL string?

MySQL: Extracting the Third Index in a String

To locate the index of the third space in a string using MySQL, one approach is to leverage the SUBSTRING_INDEX function. This function enables the extraction of a substring up to a specified delimiter, in this case, the space character.

To isolate the third space, you can utilize two nested SUBSTRING_INDEX calls. The inner function call retrieves the substring from the beginning of the string to the third space, resulting in "AAAA BBBB CCCC." The outer function call then extracts the substring from the third space to the end of the string, yielding "CCCC."

For example, consider the following query:

<code class="sql">SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(field, ' ', 3), ' ', -1)
FROM table;</code>
Copy after login

where "field" represents the space-separated string. This query would return the substring corresponding to the third index, effectively extracting "CCCC" from the given list.

The above is the detailed content of How can I extract the substring after the third space in a MySQL string?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template