@greghogg5: SQL queries are not executed in the same order that they are written by the programmer. The database engine follows a specific sequence to filter and organize the data efficiently. It starts with the FROM and JOIN clauses to identify the tables and combine the data. Next it applies the WHERE clause to filter out individual rows that do not meet the criteria. The GROUP BY clause then gathers the remaining rows into summary groups. The HAVING clause is applied after grouping to filter those specific groups. Only after these steps does the SELECT clause run to determine which columns to display. The DISTINCT keyword is then used to remove any duplicate rows from the results. The ORDER BY clause follows to sort the final list in a specific direction. Finally the LIMIT or OFFSET clauses are applied to return the exact number of rows requested.
This is interesting and educative but apart from that is not use at all. All engines will do those optimizations automatically for you before execution
2026-05-12 21:44:46
28
Maurício :
if the WHERE mentions the table mentioned in FROM it is executed before the join
2026-07-18 08:25:17
2
Rumplestiltskin :
I hope my gpt 5.5 knows this
2026-05-14 02:24:16
24
Jakob Schulz :
Those optimizations will do nothing. A push down is a very basic operation basically every execution engine will do.
2026-05-12 17:14:28
17
user2480804591279 :
should the second query not be an inner join?
2026-06-28 07:59:07
0
trex :
This has nothing to do with system design
2026-07-19 14:03:38
4
suremate :
Afaik the optimizer will handle the join vs where case.
2026-06-10 04:48:06
3
James :
why dont the syntax create following the execution order?
2026-05-13 21:25:28
3
Андрей :
why talking about performance not showing execution plan
2026-05-25 01:46:08
2
hanz :
im pretty sure your left joins wont give the same result
2026-06-25 03:42:45
1
JM :
when you include order table in your where clause you unintentional convert your left join to inner join
2026-07-17 17:56:51
1
iamklevy :
Great!
2026-05-13 00:18:49
0
steelbond :
well, duh
2026-05-13 02:02:54
0
Chung Heon :
I feel like just always filter then do whatever. that's like the only thing that you needed to know
2026-05-14 07:23:58
2
BizWise :
Insightful
2026-07-03 10:33:25
0
@sql :
thanks
2026-05-22 19:12:56
0
AJ P :
nah. its always in the use case. dont always rely on this kind of advise
2026-05-23 07:24:02
0
Banana :
keep create content like this, optimalization is so underated
2026-06-08 00:02:05
0
. :
But on The second example, the joins arent interchangeable. Select * from table1 t1 Left join table2 t2 on t1.column1 = t2.column1 and t2.column3=xzy is not the same as Select * from table1 t1 Left join table2 t2 on t1.column1 = t2.column1 where t2.column3 = xzy. They will yield different results…
2026-07-20 17:44:57
0
Greatest Comeback Reviews :
well done
2026-05-13 02:24:41
0
ABU :
i just use AI these days, they make better sql prompts
2026-05-13 12:30:07
0
kashif ahmed :
distinct?
2026-05-13 08:21:09
0
Rafael Deras :
I kinda do filtering in the Join but since I don't see too many people doing it, I thought my way was worse 🙃
2026-05-13 03:55:28
0
Cyber Investigations Podcast :
😁
2026-05-13 12:45:30
0
hellona :
💙💙💙
2026-05-26 22:40:59
0
To see more videos from user @greghogg5, please go to the Tikwm
homepage.