Clause in SQL Server

In SQL Server, a clause is a part of a SQL statement that specifies a condition or filters records from the table.  Clauses help us filter and analyze data quickly. When we have large amounts of data stored in the database, we use Clauses to query and get data required by the user.

There are several types of clauses in SQL Server, including:

  1. SELECT – Selects the records from the table
  2. WHERE – Filters out unwanted records that don\’t meet certain conditions
  3. GROUP BY – Groups similar rows into groups based on one or more columns.
  4. HAVING – Filters out groups whose aggregate value is not above or below some specified value.
  5. ORDER BY – Orders the result set by one or more columns in ascending order (ASC) or descending order (DESC).

Where Clause

The SQL WHERE clause is used to filter the results obtained by the DML statements such as SELECT, UPDATE and DELETE etc

Having Clause

The HAVING clause was introduced in SQL to allow the filtering of query results based on aggregate functions and groupings, which cannot be achieved using the WHERE clause that is used to filter individual rows.

Order By Clause

The ORDER BY command is used to sort the result set in ascending or descending order. The ORDER BY command sorts the result set in ascending order by default. To sort the records in descending order, use the DESC keyword.

Group By

The GROUP BY clause causes the rows of the items table to be collected into groups, each group composed of rows that have identical order_num values (that is, the items of each order are grouped together). After the database server forms the groups, the aggregate functions COUNT and SUM are applied within each group.