TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL SUBSTRING_INDEX Function

Overview

In this tutorial, we will learn about MySQL SUBSTRING_INDEX function with some examples. This function returns the substring from the given string string before count occurrences of the
delimiter.

Syntax

The general syntax of the function is as follows:

SUBSTRING_INDEX(<string>, <delimiter>, <count>)

The function searches the given string for the count occurrence of delimiter and returns the characters searched through when hitting the count. If the count is positive the function searches the string from the left. If the count is negative the function searches the string from the right.

The SUBSTRING_INDEX() function performs a case-sensitive search for the delimiter.

Examples

mysql> SELECT SUBSTRING_INDEX(‘www.TestingDocs.com’,’.’,1);
+———————————————-+
| SUBSTRING_INDEX(‘www.TestingDocs.com’,’.’,1) |
+———————————————-+
| www |
+———————————————-+
1 row in set (0.01 sec)

mysql> SELECT SUBSTRING_INDEX(‘www.TestingDocs.com’,’.’,-2);
+———————————————–+
| SUBSTRING_INDEX(‘www.TestingDocs.com’,’.’,-2) |
+———————————————–+
| TestingDocs.com |
+———————————————–+
1 row in set (0.00 sec)

 

MySQL SUBSTRING_INDEX Function

 

Let’s see another example, where the delimiter is not present in the given string. The function returns the whole string.

mysql> SELECT SUBSTRING_INDEX(‘www.TestingDocs.com’,’@’,1);
+———————————————-+
| SUBSTRING_INDEX(‘www.TestingDocs.com’,’@’,1) |
+———————————————-+
| www.TestingDocs.com |
+———————————————-+
1 row in set (0.00 sec)

 

SUBSTRING_INDEX Delimiter not found

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

Windows 11 Services Run Prompt

MySQL /

Start MySQL Server on Windows 11

MySQL Community Downloads TDocs

MySQL /

Download & Install MySQL on Windows 11

‹ MySQL LPAD Function› MySQL Architecture

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Print Triangle Pattern Flowchart
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version