We add clauses in a query to provide the additional facilities like filtering, storing, fetching, and grouping the records in the Table.
SQL Server Provides the following clauses,
- Order by
- Top n
- Group By
This keyword is used to filter the records from the table.
Write a query to display user details whose username is 'Den'.
Important Point to Remember
Where clauses can be used on select, update and delete Commands only.
Order By is used to arrange or sort the values either in ascending or descending order in the table.
Write a query to display user salary in the ascending order.
Write a query to display username in the descending order.
By default, the order by clause will arrange the values in ascending order.
If we want to arrange the values in descending order, then we use Desc Keyword.
Order by clause can be used on both integer and character datatypes.
It will arrange the values in a temporary manner. We cannot arrange permanently
It is used for fetching top most records from the table. Here, n will represent the number of records in the Table.
Write a query to display top 5 records from user Table.
This clause is used for dividing the similar data into groups. When we use group by clause we should use an aggregate function like count, sum, max etc.
When we implement group by clause in the query first the data in the table will be divided into separate groups based on the columns and later an aggregate function will execute on each group to get the results.
About the Author