- 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
Can we use ORDER BY NULL in MySQL?
Yes, we can do that
Note − Before MySQL 5.7, ORDER BY NULL was useful, but with MySQL 8.0, specifying ORDER BY NULL, for example, at the end to suppress implicit sorting is no longer necessary.
Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(10) -> ); Query OK, 0 rows affected (1.01 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------+ | Name | +-------+ | John | | Bob | | David | | Sam | | Mike | +-------+ 5 rows in set (0.00 sec)
Following is how you can use ORDER BY NULL in MySQL −
mysql> select *from DemoTable order by NULL;
Output
This will produce the following output −
+-------+ | Name | +-------+ | John | | Bob | | David | | Sam | | Mike | +-------+ 5 rows in set (0.00 sec)
- Related Articles
- Can we use IFNULL along with MySQL ORDER BY?
- Can we use SELECT NULL statement in a MySQL query?
- MySQL query to order by NULL values
- How can we use ORDER BY clause while calculating the Date?
- MySQL query to order by two fields and NULL values in chronological order?
- How can we create the MySQL view with ORDER BY clause?
- Can we use str_replace in MySQL?
- Can we alter order of columns in MySQL?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- How can we check for NULL in a MySQL query?
- How can we sort MySQL output in descending order?
- How can we sort MySQL output in ascending order?
- How can we use Ball-bearing in order to reduce Friction?
- How can we use prepared statements in MySQL?
- How can we use nested transactions in MySQL?

Advertisements