How SQL Query works? Execution Order Explained with Example

Navigating the SQL Query Journey: From Syntax to Results

Soma
Javarevisited

--

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?

For them the SQL query is executed as they are written but that’s not true, you can see from the above 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 20 SQL queries from interviews 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 by Javin Paul.

--

--

Soma
Javarevisited

Java and React developer, Join Medium (my favorite Java subscription) using my link 👉 https://medium.com/@somasharma_81597/membership