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

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

  2. SELECT * FROM Persons SORT 'FirstName' DESC

  3. SELECT * FROM Persons ORDER BY FirstName DESC

  4. SELECT * FROM Persons ORDER FirstName DESC


Correct Option: C

AI Explanation

To return all the records from a table named "Persons" sorted descending by "FirstName" in SQL, you can use the "ORDER BY" clause.

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

Option A) SELECT * FROM Persons SORT BY 'FirstName' DESC - This option is incorrect because the correct keyword to sort in SQL is "ORDER BY" and not "SORT BY".

Option B) SELECT * FROM Persons SORT 'FirstName' DESC - This option is incorrect because the correct keyword to sort in SQL is "ORDER BY" and not "SORT". Additionally, the syntax for specifying the column to sort by should not be enclosed in single quotes ('FirstName').

Option C) SELECT * FROM Persons ORDER BY FirstName DESC - This option is correct. It uses the "ORDER BY" clause to sort the records in descending order based on the "FirstName" column.

Option D) SELECT * FROM Persons ORDER FirstName DESC - This option is incorrect because the correct syntax to specify the column to sort by is "ORDER BY" followed by the column name. Here, the "FirstName" column is missing the "BY" keyword.

The correct answer is C. This option is correct because it uses the "ORDER BY" clause with the correct syntax to sort the records in descending order by the "FirstName" column.

Find more quizzes: