← Back to list

Written Order ≠ Execution Order in SQL — The LIMIT & OFFSET Confusion Explained

Written Order ≠ Execution Order in SQL

Sanjay Ishwar Dalawai · 2026-05-25 22:10 · 50 claps · 1.4 min read
#sql #database #limits #offset
Open on Medium ↗

Written Order ≠ Execution Order in SQL — The LIMIT & OFFSET Confusion Explained

Written Order ≠ Execution Order in SQL

One of the most confusing things for SQL beginners is this query:

LIMIT 1 OFFSET 4

At first glance, it feels like SQL should:

  1. Apply LIMIT
  2. Then apply OFFSET

Because that’s literally the order in which it is written.

But internally, SQL actually does the opposite.

It first applies:

OFFSET 4

and only after that:

LIMIT 1

And this is where an important SQL concept begins:

Written Order ≠ Execution Order

Most beginners think SQL executes exactly from left to right or top to bottom.

But databases don’t think like humans.

They optimize queries internally and execute operations in the most efficient sequence possible.

That’s why even though you write:

LIMIT 1 OFFSET 4

the database internally understands it as:

Skip 4 rows
Then return 1 row

This small confusion actually teaches a very deep concept about SQL.

The way we WRITE queries is often different from the way databases EXECUTE them internally.

And this doesn’t happen only with LIMIT and OFFSET.

Even in queries like:

SELECT *
FROM employees
WHERE salary > 50000
ORDER BY salary DESC;

the execution internally is very different from the written order.

The database first identifies the table, filters rows, processes conditions, and only later prepares the final output.

SQL is designed to look readable for humans.

But internally, databases care more about optimization and performance.

A great real-life analogy is this sentence:

“Give me 1 chocolate after skipping 4 chocolates.

Even though the sentence says “give me 1” first, your brain naturally processes:

  1. Skip 4 chocolates
  2. Then take 1

That is exactly how SQL processes LIMIT and OFFSET.

And honestly, once you understand this idea, many advanced SQL concepts suddenly start making more sense.

Because SQL is not only about writing queries.

It is about understanding how the database engine THINKS internally.


메타데이터
post_id
f12d983144f3
slug
written-order-execution-order-in-sql-the-limit-offset-confusion-explained-f12d983144f3
url
https://medium.com/@sanjaydalawai108/written-order-execution-order-in-sql-the-limit-offset-confusion-explained-f12d983144f3
canonical_url
https://medium.com/@sanjaydalawai108/written-order-execution-order-in-sql-the-limit-offset-confusion-explained-f12d983144f3
author_url
https://medium.com/@sanjaydalawai108
status
ok
fetched_at
2026-07-13 06:23:13