Which query would achieve the required result?

Examine the structure of the PROMOTIONS table:
name Null Type
PROMO_ID NOT NULL NUMBER(6)
PROMO_NAME NOT NULL VARCHAR2(30)
PROMO_CATEGORY NOT NULL VARCHAR2(30)
PROMO_COST NOT NULL NUMBER(10,2)
The management wants to see a report of unique promotion costs in each promotion category.
Which query would achieve the required result?

Examine the structure of the PROMOTIONS table:
name Null Type
PROMO_ID NOT NULL NUMBER(6)
PROMO_NAME NOT NULL VARCHAR2(30)
PROMO_CATEGORY NOT NULL VARCHAR2(30)
PROMO_COST NOT NULL NUMBER(10,2)
The management wants to see a report of unique promotion costs in each promotion category.
Which query would achieve the required result?

A.
SELECT DISTINCT promo_cost, promo_category FROM promotions;

B.
SELECT promo_category, DISTINCT promo_cost FROM promotions;

C.
SELECT DISTINCT promo_cost, DISTINCT promo_category FROM promotions;

D.
SELECT DISTINCT promo_category, promo_cost FROM promotions ORDER BY 1;



Leave a Reply 9

Your email address will not be published. Required fields are marked *


chetan

chetan

in D option why we are using 1 and 1 means

Justyna

Justyna

About ‘order by’ clause – it is allowed to use column name, column number or column alias.

Mike

Mike

Why isn’t A correct? And why is D correct? Shouldn’t Group BY be used because we want to display each promotion category?

Justyna

Justyna

Because we need promo_cost in each promo_category, not the other way around.

We use ‘Group by’ for the functions like agv, sum,max, etc.

Raj

Raj

Hi Justyna. What you said is correct. But if there are different promo_cost with same category, then we need to use “GROUP BY” function right in order to sum up the costs for that category

Alex

Alex

The answer is ambiguous. The question didn’t say anything about sorting.

innez

innez

in question no where its mentioned to sort..
then why we did “ORDER BY 1 “.

Option A can be the answer ryt?

CO

CO

A and D are both the same “data”, it’s just a matter how they see it. Doesn’t the DISTINCT return a unique “SET” ?
Thus let the management sort the report as they wish, they can have one field before the other or vica-versa however the data returned should be the same.
They could have also used the GROUP BY clause if they wished to get the same unique results, without any repeated pairs.