View the Exhibit and examine the data in the PROMO_CATEGORY and PROMO_COST columns of the
PROMOTIONS table.
Evaluate the following two queries:
SQL>SELECT DISTINCT promo_category to_char(promo_cost)”code”
FROM promotions
ORDER BY code;
SQL>SELECT DISTINCT promo_category promo_cost “code”
FROM promotions
ORDER BY 1;
Which statement is true regarding the execution of the above queries?
A.
Only the first query executes successfully.
B.
Only the second query executes successfully.
C.
Both queries execute successfully but give different results.
D.
Both queries execute successfully and give the same result.
Explanation:
Note: You cannot use column alias in the WHERE clause.
Order by followed by Alias, however the alias forgot about the double quotes
SELECT DISTINCT promo_category, to_char(promo_cost) “code”
FROM promotions
ORDER BY code;
ORA-00904: “CODE”: invalid identifier
SELECT DISTINCT promo_category, to_char(promo_cost) “CODE”
FROM promotions
ORDER BY code;
Works as expected
SELECT DISTINCT promo_category, to_char(promo_cost) “code”
FROM promotions
ORDER BY “code”;
Works as expected
B