QuestionQ47

VerifiedRestricting and Sorting Data

Refer to the Exhibit and review the data in the PROMO_CATEGORY and PROMO_COST columns of the PROMOTIONS table.

Question Image

Evaluate these 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 about execution of the preceding queries?

Explanation

Oracle permits a column alias in an ORDER BY clause, but quoted names are case-sensitive. The lowercase quoted alias "code" is not referenced by the unquoted identifier code; the first statement therefore fails. ORDER BY 1 validly sorts by the first select-list item, so the second statement executes successfully.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!