- 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
How to remove only the first word from columns values with a MySQL query?
To remove only the first word from column values, use substring(). Following is the syntax −
select substring(yourColumnName,locate(' ',yourColumnName)+1) AS anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( Title text ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Java in Depth'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable values('C++ is an object oriented programming language'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('MySQL is a relational database'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Python with data structure'); Query OK, 1 row affected (0.24 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------------------------------+ | Title | +------------------------------------------------+ | Java in Depth | | C++ is an object oriented programming language | | MySQL is a relational database | | Python with data structure | +------------------------------------------------+ 4 rows in set (0.00 sec)
Following is the query to remove the first word from column values −
mysql> select substring(Title,locate(' ',Title)+1) AS RemoveFirstWord from DemoTable;
This will produce the following output −
+--------------------------------------------+ | RemoveFirstWord | +--------------------------------------------+ | in Depth | | is an object oriented programming language | | is a relational database | | with data structure | +--------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to find the average of only first three values from a column with five values
- MySQL query to extract first word from a field?
- Select first word in a MySQL query?
- MySQL query to remove special characters from column values?
- MySQL query to remove first digit?
- MySQL query to replace only the NULL values from the table?
- MySQL query to remove string from a column with values EMP1, EMP2, EMP3, etc.
- MySQL query to remove a value with only numbers in a column
- Remove only the percentage sign from values in a MySQL table?
- Return only the first 15 characters from a column with string values in MySQL
- MySQL query to select all the records only from a specific column of a table with multiple columns
- MySQL query to retrieve only the column values with special characters?
- MySQL query to get first two highest column values from a table?
- MySQL query to display only the records that contains single word?
- MySQL query to compare and display only the rows with NULL values

Advertisements