SQL - Clauses
SQL - 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.
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