

- 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
Ordering alphabetically in MySQL except for one entry?
You can use ORDER BY clause for this. Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(200) ); Query OK, 0 rows affected (0.93 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.18 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Larry | | Carol | | Sam | | Mike | | David | +-----------+ 5 rows in set (0.00 sec)
Here is the query for ordering alphabetically except for one entry. The “FirstName” MIKE isn’t ordered −
mysql> select *from DemoTable order by FirstName="Mike",FirstName;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Carol | | David | | Larry | | Sam | | Mike | +-----------+ 5 rows in set (0.00 sec)
- Related Questions & Answers
- Display all records except one in MySQL
- Reorder integer except for value 0 with MySQL?
- How to clone a js object except for one key in javascript?
- Implement specific record ordering with MySQL
- MySQL query to ORDER BY `user_id` IN (1,2,3) AND `name` for custom ordering
- Except not working in MySQL?
- How to select all rows from a table except the last one in MySQL?
- Order by last 3 months first, then alphabetically in MySQL?
- Get Last Entry in a MySQL table?
- Selecting random entry from MySQL Database?
- How to raise an exception in one except block and catch it in a later except block in Python?
- Set Column Ordering in Bootstrap
- How to remove all objects except one or few in R?
- How to select all columns except one in a Pandas DataFrame?
- Appending an entry in one to many embedded documents with MongoDB
Advertisements