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

Difference Between ORDER BY and GROUP BY Clause: Tuples (Rows)

The document outlines the differences between SQL clauses such as ORDER BY, GROUP BY, WHERE, and HAVING. It highlights how GROUP BY groups rows with similar values, while ORDER BY sorts the result set, and explains the distinct functionalities and usage contexts of WHERE and HAVING clauses in SQL queries. Additionally, it contrasts the SYSDATE() and NOW() functions regarding their execution time outputs.

Uploaded by

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

Difference Between ORDER BY and GROUP BY Clause: Tuples (Rows)

The document outlines the differences between SQL clauses such as ORDER BY, GROUP BY, WHERE, and HAVING. It highlights how GROUP BY groups rows with similar values, while ORDER BY sorts the result set, and explains the distinct functionalities and usage contexts of WHERE and HAVING clauses in SQL queries. Additionally, it contrasts the SYSDATE() and NOW() functions regarding their execution time outputs.

Uploaded by

reshmi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like