Javarevisited Newsletter

Javarevisited Newsletter

Share this post

Javarevisited Newsletter
Javarevisited Newsletter
How SQL Queries work? Deep Dive into SQL Query Execution Order

How SQL Queries work? Deep Dive into SQL Query Execution Order

SQL queries are executed in a specific order which may be different then what you think

javinpaul's avatar
Soma's avatar
javinpaul
and
Soma
May 13, 2024
∙ Paid
24

Share this post

Javarevisited Newsletter
Javarevisited Newsletter
How SQL Queries work? Deep Dive into SQL Query Execution Order
6
Share

Hello guys, one of the common question on technical interviews about SQL is how exactly SQL query work? While this may seems simple, many programmers including experienced one fail to answer this with confidence.

Many people don’t even know how the SQL commands are executed and in which order? does the WHERE executed first or HAVING? When is filtering happen?

For them the SQL query is executed as they are written but that’s not true, you can see from the below diagram that FROM and JOIN is executed before you can SELECT anything, which is again very rational if you think through.

Earlier, I have shared How Kafka works internally, and difference between Apache Kafka, and RabbitMQ and in this article, I am going to answer how exactly SQL query works under the hood, so stay tuned and continue reading.

And, if are preparing for tech interviews and you need more questions not just queries but also database and SQL related questions from other topics like indexes, joins, group by, aggregation, and window functions then you can also checkout Grokking the SQL Interview book

This book is one of the specially designed book to prepare you for SQL interviews by answering popular questions. You an also use discount code friends20 to get 20% discount now.

How exactly SQL Query executed?

Structured Query Language (SQL) is the standard language for managing and manipulating relational databases.

It provides a powerful and efficient way to interact with data, enabling developers, analysts, and data scientists to retrieve, insert, update, and delete information from databases.

While SQL queries are written in a human-readable format, there is a complex process that occurs behind the scenes to execute these queries and retrieve the desired results.

In this article, we’ll delve into the inner workings of SQL queries, breaking down the process step by step.

1. Query Parsing and Tokenization

The journey of an SQL query begins with parsing and tokenization. When a user submits an SQL query, the database management system (DBMS) must first break down the query into individual tokens.

Keep reading with a 7-day free trial

Subscribe to Javarevisited Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
A guest post by
Soma
Java and React Developer
Subscribe to Soma
© 2025 javinpaul
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share