- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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.
Advertisements