0% found this document useful (0 votes)
140 views2 pages

SQL - Clauses

This document summarizes the main SQL clauses used to filter and organize query results. It defines the WHERE clause for filtering records by condition, the GROUP BY clause for grouping rows by column, the HAVING clause for filtering grouped results, the ORDER BY clause for sorting results, the DISTINCT clause for unique values only, and the TOP clause for limiting the number of records returned. Syntax examples are provided for each clause.

Uploaded by

Mukesh Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views2 pages

SQL - Clauses

This document summarizes the main SQL clauses used to filter and organize query results. It defines the WHERE clause for filtering records by condition, the GROUP BY clause for grouping rows by column, the HAVING clause for filtering grouped results, the ORDER BY clause for sorting results, the DISTINCT clause for unique values only, and the TOP clause for limiting the number of records returned. Syntax examples are provided for each clause.

Uploaded by

Mukesh Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CLAUSES:

WHERE CLAUSE:
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified condition.
Syntax: SELECT ProfileNM, ClientNM,
SUM(DurationNo) AS [Time
Logged], COUNT(DurationNo)
AS Count
FROM KronosCSTime
WHERE YEAR(EntryReferenceDT) = '2020'

GROUP BY:
The GROUP BY statement groups rows that have the same values into summary rows,
like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN,
SUM,AVG) to group the result-set by one or more columns.
Syntax: SELECT ProfileNM, ClientNM,
SUM(DurationNo) AS [Time
Logged], COUNT(DurationNo)
AS Count
FROM KronosCSTime
WHERE YEAR(EntryReferenceDT) =
'2020' GROUP BY ClientNM,
ProfileNM
HAVING:
The HAVING Clause enables you to specify conditions that filter which group results
appear in the results.
The WHERE clause places conditions on the selected columns, whereas the HAVING
clause places conditions on groups created by the GROUP BY clause.

Syntax: SELECT ProfileNM, ClientNM,


SUM(DurationNo) AS [Time
Logged], COUNT(DurationNo)
AS Count
FROM KronosCSTime
WHERE YEAR(EntryReferenceDT) =
'2020' GROUP BY ClientNM,
ProfileNM
HAVING COUNT(DurationNo) > 100
ORDER BY:
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
Syntax: SELECT ProfileNM, ClientNM,
SUM(DurationNo) AS [Time
Logged], COUNT(DurationNo)
AS Count
FROM KronosCSTime
WHERE YEAR(EntryReferenceDT) =
'2020' GROUP BY ClientNM,
ProfileNM
HAVING COUNT(DurationNo) > 100
ORDER BY ClientNM, ProfileNM

DISTINCT:
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only
want to list the different (distinct) values.
Syntax: SELECT DISTINCT CustomerID,
Country FROM Customers
ORDER BY CustomerID DESC

TOP:
The SELECT TOP clause is used to specify the number of records to return.
The SELECT TOP clause is useful on large tables with thousands of records. Returning a large
Number of records can impact performance.
Syntax: SELECT TOP 100 * FROM Customers

You might also like