A Level Computer Science OCR Practice Exam 2025 – Complete Study Resource

Disable ads (and more) with a membership for a one time $4.99 payment

Question: 1 / 350

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

GROUP BY

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.

FILTER

HAVING

Next

Report this question