In this tutorial we are going to learn about what is Order By in SQL and how we are going to use the order by as well as what are the conditions when we have to use the order by. so let's start.
Order by clause is used in the query when we need the rows in a sorted manner during the result. Order by clause plays an important role during performing the task, it will help to increase the readability of the output.
Now let's see the syntax of the ORDER BY and some examples to see how we can use the Order By in the query.
Syntax:
Select
[Column Name]
from
[Table Name]
Order By
[Name of the column by which you want to order the rows ],[ASC | DESC]
In the SQL Syntax
Now we are going to understand the syntax one by one
Select: Select command for selecting the column names
[Column Name]: Specify the names of the columns which you needed in the result set.
[Table Name]: Name of the table.
Order by: Order by clause.
[Name of the column]: Name of the columns by which row should be ordered.
- Column Name Expression: Column names plays an important role in the ORDER BY. By this, you can define how you can order the rows according to the column name. You can order the rows by more than 1 column. ORDER BY more than the column, the first column order the rows and according to that other columns will order the rows.
Order 1, Order 2, Order 3
SQL ORDER BY Clause Examples
Use Case in ORDER BY
Questions
Note:
1. Order by arranging the rows in the ascending ORDER BY default.
2. There is no need for a function for implementing the using the ORDER BY clause like group by.
3. Aggregate function can not be used in the ORDER BY directly, but we can use the aqqreqate function in ORDER BY by specifying the specific column name or entity in a table.
0 Comments