Clauses In SQL ServerAdd Blog

 Posted on 08/09/2018

Share On: facebook gplus twitter

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,

  • Where
  • Order by
  • Top n
  • Group By
  • Having


This keyword is used to filter the records from the table.


Write a query to display user details whose username is 'Den'.

  1. Select * from user where username ='den'  

Important Point to Remember

Where clauses can be used on select, update and delete Commands only.

Order By

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.

  1. Select * from user order by salary 


Write a query to display username in the descending order.

  1. Select * from user order by Username Desc  
Important Point to Remember

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 can be applied on select command only.

Top n

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.

  1. Select top 5 * from user  

Group By

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

Hardi Sananse
  • 75
  • 8
  • Bronze
Add Comment: