13.1k views
2 votes
Which SQL query sorts students first by age in descending order and then by address in ascending order?

Option 1:
sql
Copy code
SELECT * FROM Student ORDER BY age DESC, address ASC;
Option 2:
sql
Copy code
SELECT * FROM Student ORDER BY age DESC, address DESC;
Option 3:
sql
Copy code
SELECT * FROM Student ORDER BY age ASC, address DESC;
Option 4:
sql
Copy code
SELECT * FROM Student ORDER BY age ASC, address ASC;

1 Answer

4 votes

Final answer:

The correct SQL query for sorting by age in descending order and then by address in ascending order is Option 1: SELECT * FROM Student ORDER BY age DESC, address ASC.

Step-by-step explanation:

The SQL query that correctly sorts students first by age in descending order and then by address in ascending order is:

SELECT * FROM Student ORDER BY age DESC, address ASC;

This query is reflected in Option 1. When using the ORDER BY clause in SQL, specifying 'DESC' after a column name sorts the data in descending order, while 'ASC' sorts in ascending order. Therefore, to sort by age in descending order first and then by address in ascending order, you would list the age column followed by 'DESC' and then the address column followed by 'ASC'.

User Hanry
by
7.3k points