Oracle Database Sql Certified Associate · Free Practice Question Easy
Question 30
View and examine the following scenario.
Given: The BOOKS_TRANSACTIONS table exists in your schema in this database.
The following SQL statement has been executed.
Exhibit: 1
- SELECT *
- FROM books_transactions ORDER BY 3;
Identify the result of the query execution.
-
A
Only the three rows with the lowest values in the key column are displayed in the order that they are stored.
-
B
The first three rows in the table are displayed in the order that they are stored.
-
C
The execution fails unless the numeral 3 in the ORDER BY clause is replaced by a column name.
-
D
All table rows are displayed sorted in ascending order of the values in the third column.
Reveal correct answer
Correct answer: D
Explanation
Correct Answer:
All table rows are displayed sorted in ascending order of the values in the third column.
In the SQL statement:
- sql
- SELECT *
- FROM books_transactions
- ORDER BY 3;
The number
3in theORDER BYclause refers to the third column in theSELECTlist — not a limit on how many rows are returned.Since
SELECT *is used, all columns from theBOOKS_TRANSACTIONStable are returned, and the result is sorted by the values in the third column in ascending order by default.
Why the other options are incorrect:
“The execution fails unless the numeral 3... is replaced...” → Incorrect. Using a column position like
ORDER BY 3is valid SQL syntax.“The first three rows... are displayed...” → Incorrect. There's no row limiting in this query.
“Only the three rows with the lowest values...” → Also incorrect. Again, no row filtering or limiting.
A. If the query includes an ORDER BY clause with a LIMIT or FETCH FIRST clause, it will only return the specified number of rows based on the sorting criteria. In this case, only the three rows with the lowest values in the key column will be displayed in ascending order.
B. The default behavior of SQL queries is to return rows in the order they are stored in the table. Without an explicit ORDER BY clause, the database engine may return rows in the order they were inserted, which may not necessarily be the same as the order of the rows displayed in the table.
C. The ORDER BY clause in SQL requires specifying either a column name or an expression that evaluates to a column in the table. Using a numeral like 3 directly in the ORDER BY clause is not valid syntax and would result in a query execution failure.
D. When the ORDER BY clause specifies a numeral like 3, it refers to the position of the column in the SELECT statement. In this case, the third column in the SELECT statement is used for sorting the table rows in ascending order based on the values in that column.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
