

- 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
How can I get the records from MySQL table in result set in a particular way?
For getting the records from MySQL table in the result set in a particular way either ascending or descending, we need to use the ORDER BY clause along with ASC or DESC keywords. If we will not use any of the above-mentioned keywords then MySQL by default return the records in ascending order. The ORDER BY clause returned the result set based on a particular field (ascending or descending order) with which we will use the ORDER BY clause. Suppose we want to sort the rows of the following table −
mysql> Select * from Student; +--------+--------+--------+ | Name | RollNo | Grade | +--------+--------+--------+ | Gaurav | 100 | B.tech | | Aarav | 150 | M.SC | | Aryan | 165 | M.tech | +--------+--------+--------+ 3 rows in set (0.00 sec)
The query below sorted the table by ‘Name’ in ASCENDING order.
mysql> Select * from student order by name; +--------+--------+--------+ | Name | RollNo | Grade | +--------+--------+--------+ | Aarav | 150 | M.SC | | Aryan | 165 | M.tech | | Gaurav | 100 | B.tech | +--------+--------+--------+ 3 rows in set (0.00 sec)
The query below sorted the table by ‘Grade in DESCENDING order.
mysql> Select * from student order by Grade DESC; +--------+--------+--------+ | Name | RollNo | Grade | +--------+--------+--------+ | Aryan | 165 | M.tech | | Aarav | 150 | M.SC | | Gaurav | 100 | B.tech | +--------+--------+--------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- How can we fetch all the records from a particular MySQL table?
- How can MySQL FIND_IN_SET() function be used to get the particular record(s) from the table as a result set?
- How can I get the information about a particular column of a table by MySQL DESCRIBE statement?
- How can we get all the unique rows in MySQL result set?
- How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?
- How can I get the information about a particular column of a table by MySQL EXPLAIN statement? EXPLAIN statement?
- How can I count unique records from a column in MySQL database?
- How can we get the summary output of a column in MySQL result set itself?
- How can I return the values of columns from MySQL table as a set of values?
- How can we get only unique values of a column in MySQL result set?
- Delete all the records from a MySQL table?
- How can we fetch a particular row as output from a MySQL table?
- How can fetch records from specific month and year in a MySQL table?
- MySQL query to select records from a table on the basis of a particular month number?
- Get the number of rows in a particular table with MySQL
Advertisements