Oracle Database Sql Certified Associate · Free Practice Question Hard

Question 13

View the Exhibit and examine the structure of the PRODUCTS table.


Which two tasks would require subqueries? (Choose two)

  • A

    Display the minimum list price for each product status

  • B

    Display the total number of products supplied by supplier 102 and have product status as 'OBSOLETE'

  • C

    Display all products whose list price is more than 1000

  • D

    Display the number of products whose list prices are more than the average list price

  • E

    Display all products whose minimum list price is more than the average list price of products having the status 'orderable'

Reveal correct answers

Correct answers: D, E

Explanation

Correct Answers:

  1. Display all products whose minimum list price is more than the average list price of products having the status 'orderable'

    • You need to:

      • Compare each product’s min list price with

      • The average list price of products with status = 'orderable'

    • This requires a subquery to calculate the average list price.

    • Requires a subquery

  2. Display the number of products whose list prices are more than the average list price

    • You're comparing list prices to the overall average

    • That average must be computed in a subquery

    • Requires a subquery

Incorrect Options:

Display the total number of products supplied by supplier 102 and have product status as 'OBSOLETE'

  • Can be done with a single SELECT + WHERE clause + COUNT()

  • Does not require a subquery


Display all products whose list price is more than 1000

  • Simple WHERE condition:

  • Does not require a subquery


Display the minimum list price for each product status

  • This can be done with a GROUP BY:

  • Does not require a subquery


In Oracle, a subquery is a query within a query. You can create subqueries within your SQL statements. These subqueries can reside in the WHERE clause, the FROM clause, or the SELECT clause.

WHERE clause

Most often, the subquery will be found in the WHERE clause. These subqueries are also called nested subqueries.

For example:



Limitation: Oracle allows up to 255 levels of subqueries in the WHERE clause.

FROM clause

A subquery can also be found in the FROM clause. These are called inline views.

For example:



In this example, we've created a subquery in the FROM clause as follows:



This subquery has been aliased with the name subquery1. This will be the name used to reference this subquery or any of its fields.


Limitations

Oracle allows an unlimited number of subqueries in the FROM clause.

SELECT clause

A subquery can also be found in the SELECT clause.

For example:



In this example, we've created a subquery in the SELECT clause as follows:



The subquery has been aliased with the name subquery2. This will be the name used to reference this subquery or any of its fields.

The trick to placing a subquery in the select clause is that the subquery must return a single value. This is why an aggregate function such as SUM function, COUNT function, MIN function, or MAX function is commonly used in the subquery.


A. This task requires a subquery to retrieve the minimum list price for each distinct product status, as it involves aggregating data based on different product statuses to display the desired result.

B. This task does not require a subquery as it involves filtering products based on specific criteria (supplier ID and product status) without the need for additional calculations or comparisons.

C. This task does not require a subquery as it involves a simple comparison of list prices with a fixed value (1000) without the need for additional calculations or comparisons.

D. This task requires a subquery to calculate the average list price of all products and then compare it with the list prices of individual products to determine the number of products that meet the specified condition.

E. This task requires a subquery to calculate the average list price of products with the status 'orderable' and then compare it with the minimum list price of all products to display the desired result.

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