- 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
MySQL query to split the string “Learn With Ease” and return the last word?
For this, you can use SUBSTRING_INDEX(). Let us first create a table −
mysql> create table DemoTable ( Words TEXT ); Query OK, 0 rows affected (1.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Learn With Ease'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Intro To MySQL'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('Deep Dive Using Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('C++ In Depth'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------------------+ | Words | +-----------------------+ | Learn With Ease | | Intro To MySQL | | Deep Dive Using Java | | C++ In Depth | +-----------------------+ 4 rows in set (0.00 sec)
Following is the query to split the string “Learn With Ease” and return the last word −
mysql> update DemoTable set Words=substring_index(Words,' ',-1); Query OK, 4 rows affected (0.28 sec) Rows matched : 4 Changed : 4 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------+ | Words | +----------+ | Ease | | MySQL | | Java | | Depth | +----------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to extract last word from a field?
- MySQL query to search exact word from string?
- Getting last 5 character of a string with MySQL query?
- MySQL query to replace a string after the last / in a column with directory links?
- MySQL query to sort by certain last string character?
- MySQL query to return 5 random records from last 20 records?
- MySQL query to return the entire date and time based on a string and format
- MySQL query to check if a string contains a word?
- Possible to split a string with separator after every word in JavaScript
- MySQL query to find the number of rows in the last query
- MySQL query to get a substring from a string except the last three characters?
- MySQL Query to remove all characters after last comma in string?
- PHP program to find the length of the last word in the string
- MySQL SELECT query to return records with specific month and year
- MySQL query to return multiple row records with AND & OR operator

Advertisements