You work as a database administrator at ABC.com. You study the exhibit carefully. Exhibit
Using the PROMOTIONS table, you need to display the names of all promos done after
January 1, 2001 starting with the latest promo. Which query would give the required result?
(Choose all that apply.)
A.
SELECT promo_name,promo_begin_date FROM promotions WHERE
promo_begin_date > ’01-JAN-01′ ORDER BY 1 DESC;
B.
SELECT promo_name,promo_begin_date “START DATE” FROM promotions WHERE
promo_begin_date > ’01-JAN-01′ ORDER BY “START DATE” DESC;
C.
SELECT promo_name,promo_begin_date FROM promotions WHERE
promo_begin_date > ’01-JAN-01′ ORDER BY 2 DESC;
D.
SELECT promo_name,promo_begin_date FROM promotions WHERE
promo_begin_date > ’01-JAN-01′ ORDER BY promo_name DESC;
C is correct,
B is not correct. you can’t use the column alias “START DATE” in the order by.
B and C are both correct.
You can use the column alias in the order by.
Try it in a test database, it works fine.
Yes , B & C are the correct answers
You can use column alias in the order by but you have to use ” “.
If you will not use ” ” . then it will throw error –
SQL> select FILE#,CREATION_TIME “Start_date” from v$datafile order by Start_date desc;
select FILE#,CREATION_TIME “Start_date” from v$datafile order by Start_date desc
*
ERROR at line 1:
ORA-00904: “START_DATE”: invalid identifier
SQL> select FILE#,CREATION_TIME “Start_date” from v$datafile order by “Start_date” desc;
FILE# Start_dat
———- ———
10 ##########