Prepare for the A Level Computer Science OCR Exam with engaging quiz questions and interactive flashcards. Get ready to excel in your exam with comprehensive study materials designed to bolster your knowledge and confidence.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What keyword in SQL is used to specify the fields that should be sorted in a record?

  1. GROUP BY

  2. ORDER BY

  3. FILTER

  4. HAVING

The correct answer is: ORDER BY

The keyword used in SQL to specify the fields that should be sorted in a record is "ORDER BY." This clause allows you to define the order in which the results of a query are to be presented. By using "ORDER BY," you can sort the data either in ascending order (the default) or descending order by including the "ASC" or "DESC" keywords, respectively. For example, if you have a table of employees and you want to display them sorted by their last names, you would use a query like: ```sql SELECT * FROM employees ORDER BY last_name ASC; ``` This will present the records sorted by the `last_name` field in ascending order. The other keywords are used for different purposes in SQL. "GROUP BY" is used to group rows that have the same values in specified columns into summary rows. "FILTER" is not a standard SQL keyword; it is applied in certain contexts (like in window functions) but not for sorting records. "HAVING" is used to filter results after aggregation has occurred, specifically with GROUP BY results. Thus, "ORDER BY" is the correct choice when it comes to sorting fields in SQL queries.