Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.1 SQL commands

Sample Question

3.59

Answer the result of executing "SELECT * FROM t1 ORDER BY id LIMIT 5 OFFSET 1;" on the following table.

postgres=# SELECT * FROM t1;
 id | name
----+------
  1 | aaa
  3 | ccc
  2 | bbb
  4 | ddd

A.  id | name
   ----+------
     1 | aaa
     3 | ccc
     2 | bbb
     4 | ddd

B.  id | name
   ----+------
     3 | ccc
     2 | bbb
     4 | ddd

C.  id | name
   ----+------
     2 | bbb
     3 | ccc
     4 | ddd

D. An error is output because the LIMIT value is greater than the total number of rows.

※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/10

Answer and Explanation

LIMIT and OFFSET are used to specify the number of items to be output in a SELECT statement.
LIMIT specifies the upper limit, and OFFSET specifies how many items to skip from the beginning.
It does not cause an error even if LIMIT is greater than the actual number of data items.
When ORDER BY is used together, LIMIT and OFFSET are performed on the sorted results, and the output results are also sorted.

Therefore, the correct answer is C.