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

How can I sort the rows in a meaningful way?

王林
Release: 2023-08-23 19:41:02
forward
622 people have browsed it

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)
Copy after login

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template