With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?

  1. SELECT * FROM Persons SORT 'FirstName' DESC ;

  2. SELECT * FROM Persons ORDER BY FirstName DESC;

  3. SELECT * FROM Persons ORDER FirstName DESC ;

  4. SELECT * FROM Persons SORT BY 'FirstName' DESC ;


Correct Option: B

AI Explanation

To answer this question, you need to understand the syntax of the SQL SELECT statement and the ORDER BY clause.

The correct answer is B) SELECT * FROM Persons ORDER BY FirstName DESC;

Let's go through each option to understand why it is correct or incorrect:

Option A) SELECT * FROM Persons SORT 'FirstName' DESC; This option is incorrect because the correct keyword to use for sorting in SQL is ORDER BY, not SORT. Additionally, the column name should not be enclosed in single quotes.

Option B) SELECT * FROM Persons ORDER BY FirstName DESC; This option is correct because it uses the correct syntax for sorting records in descending order. The ORDER BY clause is used to sort the records based on the column specified (in this case, FirstName), and the DESC keyword is used to specify descending order.

Option C) SELECT * FROM Persons ORDER FirstName DESC; This option is incorrect because the ORDER keyword is missing before the column name. The correct syntax is ORDER BY.

Option D) SELECT * FROM Persons SORT BY 'FirstName' DESC; This option is incorrect because the correct keyword to use for sorting in SQL is ORDER BY, not SORT. Additionally, the column name should not be enclosed in single quotes.

The correct answer is B) SELECT * FROM Persons ORDER BY FirstName DESC. This option is correct because it uses the correct syntax for sorting records in descending order.

Find more quizzes: