1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. SELECT * FROM events LIMIT 10; is run repeatedly on a…

Added 30 Nov -0001

SELECT * FROM events LIMIT 10; is run repeatedly on a large table. Why can the returned rows differ between executions?

  1. LIMIT samples rows randomly unless a repeatable seed is supplied with the statement
  2. Without ORDER BY no row order is guaranteed, so the plan may return any ten rows Correct answer
  3. LIMIT is applied before the WHERE clause, so different rows qualify on each run
  4. The table's primary key is used implicitly, and keys are regenerated on each read

Correct answer

B. Without ORDER BY no row order is guaranteed, so the plan may return any ten rows

16 views

MCQSEXAM

Explanation

LIMIT without ORDER BY is non-deterministic because SQL never promises row order: a sequential scan, an index scan or a parallel plan may each return a different arbitrary subset. Adding ORDER BY on a unique key makes the result stable and reproducible. The same reasoning applies to pagination with OFFSET, where unstable ordering can repeat or skip rows.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs