- 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
Implement specific record ordering with MySQL
To set specific record ordering, use ORDER BY LIKE. Let us first create a table−
mysql> create table DemoTable808(Value varchar(100)); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable808 values('smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable808 values('Adamsmith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable808 values('Carolsmith'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable808 values('smithJohn'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable808;
This will produce the following output −
+------------+ | Value | +------------+ | smith | | Adamsmith | | Carolsmith | | smithJohn | +------------+ 4 rows in set (0.00 sec)
Following is the query to set specific ordering −
mysql> select *from DemoTable808 order by case when Value like 'smith%' then 0 else 1 end asc,Value asc;
This will produce the following output −
+------------+ | Value | +------------+ | smith | | smithJohn | | Adamsmith | | Carolsmith | +------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL CONCAT a specific column value with the corresponding record
- Replace a specific duplicate record with a new value in MySQL
- Search record with a specific value in MySQL using LIKE or REGEXP?
- Display only a specific duplicate record in MySQL
- Fetch a specific record using a single MySQL query with AND & OR operator
- How do I exclude a specific record in MySQL?
- How to select record except the lower value record against a specific value in MySQL?
- MySQL query to place a specific record on the top
- How to find a specific record from a list of values with semicolon in MySQL?
- Implement CASE statement with WHEN clause to check for the existence of a record in MySQL
- Sort list of tuples by specific ordering in Python
- Delete a specific record on the basis of EmployeeId in MySQL
- Filtering data in a table for a required condition to eliminate a specific record with MySQL
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- MySQL query to decrease the value of a specific record to zero?

Advertisements