- 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
In MySQL, how it can be possible to specify a sort order using a column that is not retrieved by the query?
Actually, as we know that we can specify a sort order with the help of the ORDER BY clause. We need to write the ORDER BY keyword followed by the name of the column on which we want to sort the table. It is not necessary that we have to use that column name after the SELECT keyword in the query.
Example
mysql> Select Sr, Item from ratelist ORDER BY Price; +----+------+ | Sr | Item | +----+------+ | 5 | T | | 1 | A | | 2 | B | | 4 | h | | 3 | C | +----+------+ 5 rows in set (0.00 sec)
In the example above, we can observe that we need not write the name of the same column after the SELECT keyword which we write in ORDER BY keyword to sort the table. It means that the column itself would not be retrieved by MySQL query on the basis of which we have sorted out the table.
- Related Articles
- MySQL Order By date column and integer column, but specify ordering rules of integer column? Is it possible?
- While using the ROLLUP modifier, is it possible to use a MySQL ORDER BY clause to sort the result?
- How can we sort a query using ORDER BY CASE WHEN REGEXP?
- How can it be possible to invert a string in MySQL?
- Is it possible to calculate a correlation in a MySQL query?
- MySQL “order by” inside of “group by”? Is it possible?
- Is it possible to sort varchar data in ascending order that have both string and number values with MySQL?
- How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?
- How can you order the result obtained by select query in MySQL?
- How to sort by value with MySQL ORDER BY?
- What to assign to a MySQL column that must not be empty?
- How to ORDER BY FIELD with GROUP BY in a single MySQL query?
- How can it be possible to add 3 months interval in a MySQL date without using the word ‘Months’ with interval?
- How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?
- Can I get Age using BirthDate column in a MySQL query?

Advertisements