![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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)
Advertisements