

- 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
Sort a column ignoring a specific word in MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> Name text -> ); Query OK, 0 rows affected (1.31 sec)
Insert some records in the table using insert command. Here, we have inserted a name with a specific word “name”, which we need to ignore −
mysql> insert into DemoTable values('John 7'); Query OK, 1 row affected (0.65 sec) mysql> insert into DemoTable values('John 6'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('John 9'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values('name John 3'); Query OK, 1 row affected (0.24 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------------+ | Name | +-------------+ | John 7 | | John 6 | | John 9 | | name John 3 | +-------------+ 4 rows in set (0.00 sec)
Following is the query to ignore a specific word while sorting a column −
mysql> select *from DemoTable ORDER BY TRIM(REPLACE(LOWER(Name), 'name ', ''));
Output
This will produce the following output −
+-------------+ | Name | +-------------+ | name John 3 | | John 6 | | John 7 | | John 9 | +-------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- ORDER BY a specific word in MySQL
- Swap a specific column value in MySQL
- How can I get the number of times a specific word appears in a column with MySQL?
- Remove specific word in a comma separated string with MySQL
- Fetch values by ignoring a specific one in JavaScript?
- Fetch a specific column value (name) in MySQL
- MySQL query to sort column values and ignoring quotes on one of the values
- Replace only a specific value from a column in MySQL
- Adding new column after a specific column and defining a default in MySQL?
- Place a specific value for NULL values in a MySQL column
- How to use a single MySQL query to count column values ignoring null?
- Sum up values in a single MySQL column in a specific way?
- MySQL query to split a column after specific characters?
- MySQL query to count rows with a specific column?
- MySQL random rows sorted by a specific column name?
Advertisements