Which command sorts records in ascending or descending order in SQL?

Study for the OCR GCSE Computer Science Exam. Prepare with flashcards, multiple choice questions, and hints. Get exam-ready with practical questions and answers!

The command that sorts records in ascending or descending order in SQL is "ORDER BY". This command is used in SQL queries to specify the specific column or columns that should be used for sorting the result set. By default, the sorting is done in ascending order, but you can explicitly specify descending order by using the keyword "DESC" following the column name.

For example, if you want to sort a list of customers based on their last names in ascending order, you would use a command like:


SELECT * FROM customers

ORDER BY last_name ASC;

If you wanted to sort it in descending order, you would write:


SELECT * FROM customers

ORDER BY last_name DESC;

This specific functionality of "ORDER BY" is essential in data retrieval, as it allows users to easily analyze data in a structured manner based on their specific needs.

The other commands serve different purposes; "WHERE" is used to filter records based on specific conditions, "UPDATE" modifies existing records in a table, and "LIKE" is used in the context of pattern matching for string comparison. These commands do not have inherent sorting functionality.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy