Evaluate these two SQL statements:
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY salary DESC;
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY 2 DESC;
What is true about them?
Evaluate these two SQL statements:
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY salary DESC;
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY 2 DESC;
What is true about them?
The two SQL statements produce identical results. The first statement explicitly orders by the salary column in descending order. The second statement orders by the second column in the SELECT clause, which is also the salary column, in descending order. Therefore, both statements will order the results by the salary column in descending order, leading to identical results.
column aliases and/or number as order in the select for the col are allowed in order by clause. default is ASC so DESC is needed