
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- How can MySQL FIND_IN_SET() function be used to get the particular record(s) from the table as a result set?
- How can we fetch all the records from a particular MySQL table?
- How can we get all the unique rows in MySQL result set?
- How can I get the information about a particular column of a table by MySQL DESCRIBE statement?
- How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?
- How can we get the summary output of a column in MySQL result set itself?
- How can we get only unique values of a column in MySQL result set?
- How can I get the information about a particular column of a table by MySQL EXPLAIN statement?\nEXPLAIN statement?
- How can I count unique records from a column in MySQL database?
- How can fetch records from specific month and year in a MySQL table?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- How can I return the values of columns from MySQL table as a set of values?
- How can we fetch a particular row as output from 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