Home  >  Article  >  Database  >  How can I sort the rows in a meaningful way?

How can I sort the rows in a meaningful way?

王林
王林forward
2023-08-23 19:41:02560browse

How can I sort the rows in a meaningful way?

To sort the rows in a meaningful way, we can 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 following query sorts the table by ‘Name’.

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 sorts the table by 'Grade'.

mysql> Select * from student order by Grade;
+--------+--------+--------+
| Name   | RollNo | Grade  |
+--------+--------+--------+
| Gaurav |    100 | B.tech |
| Aarav  |    150 | M.SC   |
| Aryan  |    165 | M.tech |
+--------+--------+--------+
3 rows in set (0.00 sec)

The above is the detailed content of How can I sort the rows in a meaningful way?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete