- 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
Perform MySQL ORDER BY keyword match?
For this, let us create a table, insert some values and use ORDER BY CASE. Let us first create a table −
mysql> create table DemoTable602 (GameName text); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable602 values('Candy cash game'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable602 values('Pubg'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable602 values('cash Candy game'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable602 values('subway'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable602;
This will produce the following output −
+-----------------+ | GameName | +-----------------+ | Candy cash game | | Pubg | | cash Candy game | | subway | +-----------------+ 4 rows in set (0.00 sec)
Following is the query to perform MySQL ORDER BY keyword match −
mysql> select *from DemoTable602 order by CASE WHEN instr(GameName, 'Candy') = 0 then 1 else 0 end, instr(GameName, 'cash') desc;
This will produce the following output −
+-----------------+ | GameName | +-----------------+ | Candy cash game | | cash Candy game | | Pubg | | subway | +-----------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to perform sort order on same field
- MySQL Order by with case?
- MySQL Order By specific strings?
- MySQL Order by beginning letter?
- Perform complex MySQL insert by using CONCAT()?
- Order By date ASC in MySQL?
- Order by selected record in MySQL?
- MySQL ORDER BY strings with underscore?
- Order MySQL query by multiple ids?
- MySQL ORDER BY with CASE WHEN
- MySQL ORDER BY with EXPLAIN command
- MySQL order by string with numbers?
- Resolve Syntax error near “ORDER BY order DESC” in MySQL?
- How to sort by value with MySQL ORDER BY?
- How to order by timestamp in MySQL?

Advertisements