SQL – Clause Group By, Having and Order By Command

Group By Clause:Group By clause is used to display rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate duplicate rows from a result set.

SELECT Employee, SUM (Hours)
FROM EmployeeHours
GROUP BY Employee

Having Clause: Having clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate.

SELECT Employee, SUM (Hours)
FROM EmployeeHours
GROUP BY Employee
HAVING SUM (Hours) > 24

Order By Clause: Order By clause identifies which columns are used to sort the output data, and how they should be sorted (ascending or descending). Without an ORDER BY clause, the order of rows returned by an SQL query is undefined. Use of Order By option in Select

SELECT * FROM Table_Name
ORDER BY DOB

For Multiple Column Sort:

SELECT *

FROM Table_name

ORDER BY Column1, Column2;

Use Order by  for Ascending /Descending

SELECT * FROM Customers
ORDER BY DOB ASC/DESC

Design a site like this with WordPress.com
Get started