Introduction

In this tutorial, we want to select data from a table and sort the result set. In order to do this, we use the SELECT Statement with the ORDER BY Clause.

We have already created the table student with the following data:

Example 1 - Sort rows in ascending order

We want to select all records from the table student and sort the result set by the column name in ascending order.

In order to do this, we execute the following SQL statement:

SELECT * FROM student
ORDER BY name;

The following selection is returned:

Example 2 - Sort rows in descending order

We want to select all records from the table student and sort the result set by the column name in descending order.

In order to do this, we execute the following SQL statement:

SELECT * FROM student
ORDER BY name DESC;

The following selection is returned:

Conclusion

Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to select data from a table and sort the result set. We can simply use the SELECT Statement with the ORDER BY Clause. Try it yourself!

Instagram

Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.