Difference Between ORDER BY and GROUP BY Clause
The following table summarises the key differences:
GROUP BY ORDER BY
Whereas Order by statement sort the
Group by statement is used to group the rows that
result-set either in ascending or descending
have the same value.
order.
While it does not use in CREATE VIEW
It may be allowed in CREATE VIEW statement.
statement.
In select statements, it is always used before the While in the select statement, it is always
order by keyword. used after the group by keyword.
An attribute cannot be in the group by a Whereas in order by statement, the
statement under the aggregate function. attribute can be under aggregate function.
In group by clause, the tuples are grouped based Whereas in order by clause, the result set is
on the similarity between the attribute values of sorted based on ascending or descending
tuples. order.
Group by controls the presentation While order by clause controls the
of tuples(rows). presentation of columns.
2. The difference between the SYSDATE() and NOW() functions is that the SYSDATE() function returns
the exact time at which the function executes. On the other hand, the NOW() function returns the
current date and time at the beginning of the statement execution.
3. Difference Between WHERE and HAVING Clause in SQL
Before going into examples, it’s important to understand the distinctions between the WHERE and
HAVING clauses. The table below outlines their key differences for a clear comparison.
WHERE Clause HAVING Clause
Filters rows before groups are aggregated. Filters groups after the aggregation process..
WHERE Clause can be used without GROUP BY HAVING Clause can be used with GROUP BY
WHERE Clause HAVING Clause
Clause Clause
HAVING Clause implements in column
WHERE Clause implements in row operations
operation
WHERE Clause cannot contain aggregate
HAVING Clause can contain aggregate function
function
WHERE Clause can be used with SELECT, HAVING Clause can only be used with SELECT
UPDATE, DELETE statement. statement.
WHERE Clause is used before GROUP BY
HAVING Clause is used after GROUP BY Clause
Clause
WHERE Clause is used with single row function HAVING Clause is used with multiple row
like UPPER, LOWER etc. function like SUM, COUNT etc.