

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 get substring results from a table with file location recordsi in MySQL?
To fetch sub strings, use the substr() method in MySQL as in the below syntax −
select substr(yourColumnName,startIndex,endIndex) from yourTableName limit anyValue; select substr(yourColumnName,startIndex+endIndex) from yourTableName limit anyValue;
Let us create a table −
mysql> create table demo11 −> ( −> id int NOT NULL AUTO_INCREMENT PRIMARY KEY, −> fileLocation text −> ); Query OK, 0 rows affected (2.60 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo11(fileLocation) values('E:/users/program/sample.sql'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo11(fileLocation) values('E:/users/data/db.sql'); Query OK, 1 row affected (0.32 sec) mysql> insert into demo11(fileLocation) values('C:/users/data/sample2.sql'); Query OK, 1 row affected (0.13 sec)
Display records from the table using select statement −
mysql> select *from demo11;
This will produce the following output −
+----+-----------------------------+ | id | fileLocation | +----+-----------------------------+ | 1 | E:/users/program/sample.sql | | 2 | E:/users/data/db.sql | | 3 | C:/users/data/sample2.sql | +----+-----------------------------+ 3 rows in set (0.00 sec)s
Here is the query to get sub string result in multiple lines.
The first part query is as follows −
mysql> select substr(fileLocation,1,15) from demo11 limit 1,2;
This will produce the following output −
+---------------------------+ | substr(fileLocation,1,15) | +---------------------------+ | E:/users/data/d | | C:/users/data/s | +---------------------------+ 2 rows in set (0.00 sec)
The second part is as follows −
mysql> select substr(fileLocation,16) from demo11 limit 1,2;
This will produce the following output −
+-------------------------+ | substr(fileLocation,16) | +-------------------------+ | b.sql | | ample2.sql | +-------------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Populating a table from query results in MySQL?
- How to get left substring in MySQL from a column with file path? Display the entire file path string excluding the file name?
- How to substring value in a MySQL table column?
- Sort search results based on substring position in MySQL
- Get only the file extension from a column with file names as strings in MySQL?
- How can we extract a substring from the value of a column in MySQL table?
- How to get the second last record from a table in MySQL?
- Get the last record from a table in MySQL database with Java?
- Updating a MySQL table with values from another table?
- How can we get substring from a string in Python?
- MySQL query to get a substring from a string except the last three characters?
- Get the substring of a column in MySQL
- How to get the top 3 salaries from a MySQL table with record of Employee Salaries?
- How to merge MySQL results?
- How to get file name from a path in PHP?
Advertisements