- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get part of a string based on a character in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> Code varchar(100) -> ); Query OK, 0 rows affected (1.07 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('/101/102/106'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('/110/111/101'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('/111/114/201'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('/111/118'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------------+ | Code | +--------------+ | /101/102/106 | | /110/111/101 | | /111/114/201 | | /111/118 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to get part of a string in based on a character −
mysql> select SUBSTRING_INDEX(SUBSTRING_INDEX(Code,'/',3),'/',-1) from DemoTable;
Output
This will produce the following output −
+-----------------------------------------------------+ | SUBSTRING_INDEX(SUBSTRING_INDEX(Code,'/',3),'/',-1) | +-----------------------------------------------------+ | 102 | | 111 | | 114 | | 118 | +-----------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to get a part of string after a specified character in JavaScript?
- Encoding string based on character frequency in JavaScript
- Constructing a string based on character matrix and number array in JavaScript
- Get left part of the string on the basis of last occurrence of delimiter in MySQL?
- Creating String Object from certain part of a character Array in Java
- MySQL query to append a number of stars based on string length?
- Split the left part of a string by a separator string in MySQL?
- Update a column value, replacing part of a string in MySQL?
- How to escape '%' character on the left and middle part of strings in a MySQL column?
- How to create a subset based on levels of a character column in R?
- How to apply Substring() for fields in MySQL to get part of string?
- Returning acronym based on a string in JavaScript
- How to cut part of a string with a MySQL query?
- How to order by certain part of a string in MySQL?
- Fetch middle part of a string surrounded by slash in MySQL

Advertisements