Oracle Database Sql Certified Associate · Free Practice Question Medium

Question 36

View and examine the following available responses.

Identify the true statements regarding the SQL WHERE and HAVING clauses. (Choose three)

  • A

    The HAVING clause is used to exclude one or more aggregated results after grouping data.

  • B

    The HAVING clause conditions can use aliases for the columns.

  • C

    The WHERE and HAVING clauses cannot be used together in a SQL statement.

  • D

    The WHERE clause is used to exclude rows before grouping data.

  • E

    The HAVING clause conditions can have aggregating functions.

Reveal correct answers

Correct answers: A, D, E

Explanation

Let's evaluate each of the given statements about the WHERE and HAVING clauses, and identify the three true ones.

True Statements:

  1. The HAVING clause conditions can have aggregating functions.
    True – The HAVING clause is specifically designed to filter on aggregated values, like:

  2. The WHERE clause is used to exclude rows before grouping data.
    True – WHERE filters individual rows before GROUP BY is applied.

  3. The HAVING clause is used to exclude one or more aggregated results after grouping data.
    True – HAVING is used after aggregation, for example:

False Statements:

  1. The HAVING clause conditions can use aliases for the columns.
    False – You typically cannot use an alias defined in the SELECT clause inside HAVING. You should repeat the full expression or use the aggregate directly.

  2. The WHERE and HAVING clauses cannot be used together in a SQL statement.
    False – You can absolutely use both together:


Where and Having

  • WHERE clause executes just after FROM clause.

  • WHERE comes before the group by clause

  • WHERE cannot use group functions

  • WHERE clause restricts few rows from taking part in any other operation like joins, functions etc...


  • HAVING comes after the group by clause

  • HAVING can use the aggregate / group functions like MAX , MIN , AVG, SUM, etc.

  • HAVING clause just hides few rows from your eyes from the result set produced by the query.

  • HAVING is the last clause to be executed.


Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.

A. The HAVING clause is used to filter grouped data after the GROUP BY clause has been applied. It allows for the exclusion of aggregated results based on specific conditions, providing a way to filter the grouped data based on aggregate values.

B. The HAVING clause operates on the result set that is produced by the GROUP BY clause. It can reference the column aliases defined in the SELECT statement, making it possible to use aliases in the conditions specified in the HAVING clause.

C. The WHERE and HAVING clauses serve different purposes in a SQL statement. The WHERE clause is used to filter rows before any grouping is done, while the HAVING clause is used to filter grouped data after the grouping has been applied. They can be used together in a SQL statement to apply both row-level and group-level filters.

D. The WHERE clause is used to filter rows before any grouping is done in a SQL statement. It is applied to individual rows in the result set, excluding rows that do not meet the specified conditions before any grouping is performed.

E. The HAVING clause is used to filter rows after the GROUP BY clause has grouped the data. It allows the use of aggregating functions such as SUM, AVG, COUNT, etc., to filter the grouped data based on specific conditions.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need