
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to extract substring from a sting starting at a particular position in MySQL?
For this, you can use the mid() function. Following is the syntax −
select mid(yourColumnName, yourPositionToStart, yourEndValue) as anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('My best framework is Spring and Hibernate'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-------------------------------------------+ | Title | +-------------------------------------------+ | My best framework is Spring and Hibernate | +-------------------------------------------+ 1 row in set (0.00 sec)
Here is the query to get part of a string in MySQL. We are trying to get 30 characters beginning from character 21. If the count of characters after 21 are not 30, then only the remaining characters will get displayed −
mysql> select mid(Title,21,30) as partofString from DemoTable;
Output
+-----------------------+ | partofString | +-----------------------+ | Spring and Hibernate | +-----------------------+ 1 row in set (0.00 sec)
- Related Articles
- How can we extract a substring from a string in MySQL?
- How to extract strings that contains a particular substring in an R vector?
- How to extract a substring from inside a string in Python?
- In MySQL, how can we insert a substring at the specified position in a string?
- How can we extract a substring from the value of a column in MySQL table?
- How to extract certain substring from a string using Java?
- C# program to remove characters starting at a particular index in StringBuilder
- Extract a particular element from a nested array in MongoDB
- How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?
- How to sort a particular value at the end in MySQL?
- Java program to extract ‘k’ bits from a given position
- Python program to extract ‘k’ bits from a given position?
- The listIterator() method of CopyOnWriteArrayList in Java starting at a specified position
- Python Program that extract words starting with Vowel From A list
- MySQL order from a different starting value?

Advertisements