SQL: The Complete Reference - https://lnkd.in/eaz53F7i Look for "Read and Download Links" section to download. Follow me if you like this post. #SQL #Databases #DataAnalysis #DataScience #LLMs #GenAI #GenerativeAI
Things Every Developer Should Know — SQL Execution Order. A SQL query executes its statements in the following order: 1) FROM / JOIN 2) WHERE 3) GROUP BY 4) HAVING 5) SELECT 6) DISTINCT 7) ORDER BY 8) LIMIT / OFFSET 𝗧𝗵𝗲 𝘁𝗲𝗰𝗵𝗻𝗶𝗾𝘂𝗲𝘀 𝘆𝗼𝘂 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁 𝗮𝘁 𝗲𝗮𝗰𝗵 𝘀𝘁𝗲𝗽 𝗵𝗲𝗹𝗽 𝘀𝗽𝗲𝗲𝗱 𝘂𝗽 𝘁𝗵𝗲 𝗳𝗼𝗹𝗹𝗼𝘄𝗶𝗻𝗴 𝘀𝘁𝗲𝗽𝘀. This is why it's important to know their execution order. 𝗧𝗼 𝗺𝗮𝘅𝗶𝗺𝗶𝘇𝗲 𝗲𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝗰𝘆, 𝗳𝗼𝗰𝘂𝘀 𝗼𝗻 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗶𝗻𝗴 𝘁𝗵𝗲 𝘀𝘁𝗲𝗽𝘀 𝗲𝗮𝗿𝗹𝗶𝗲𝗿 𝗶𝗻 𝘁𝗵𝗲 𝗾𝘂𝗲𝗿𝘆. With that in mind, let's take a look at some 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝘁𝗶𝗽𝘀: 𝟭) 𝗠𝗮𝘅𝗶𝗺𝗶𝘇𝗲 𝘁𝗵𝗲 𝗪𝗛𝗘𝗥𝗘 𝗰𝗹𝗮𝘂𝘀𝗲 This clause is executed early, so it's a good opportunity to reduce the size of your data set before the rest of the query is processed. 𝟮) 𝗙𝗶𝗹𝘁𝗲𝗿 𝘆𝗼𝘂𝗿 𝗿𝗼𝘄𝘀 𝗯𝗲𝗳𝗼𝗿𝗲 𝗮 𝗝𝗢𝗜𝗡 Although the FROM/JOIN occurs first, you can still limit the rows. To limit the number of rows you are joining, use a subquery in the FROM statement instead of a table. 𝟯) 𝗨𝘀𝗲 𝗪𝗛𝗘𝗥𝗘 𝗼𝘃𝗲𝗿 𝗛𝗔𝗩𝗜𝗡𝗚 The HAVING clause is executed after WHERE & GROUP BY. This means you're better off moving any appropriate conditions to the WHERE clause when you can. 𝟰) 𝗗𝗼𝗻'𝘁 𝗰𝗼𝗻𝗳𝘂𝘀𝗲 𝗟𝗜𝗠𝗜𝗧, 𝗢𝗙𝗙𝗦𝗘𝗧, 𝗮𝗻𝗱 𝗗𝗜𝗦𝗧𝗜𝗡𝗖𝗧 𝗳𝗼𝗿 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝘁𝗲𝗰𝗵𝗻𝗶𝗾𝘂𝗲𝘀 It's easy to assume that these would boost performance by minimizing the data set, but this isn’t the case. Because they occur at the end of the query, they make little to no impact on its performance. If you want to create efficient queries, it's a good idea to understand how things work under the hood otherwise your efforts may be wasted. While these tips work best in most cases, you should consider your unique use case when choosing the best course of action. Follow Sai Reddy for more such posts! SRProSkillBridge Reach out to me to attend mock interviews that will help you prepare and crack your next interview with confidence. Book 1:1- https://lnkd.in/gsrnePyD page- https://lnkd.in/gmQQGgns website- https://lnkd.in/g6afVJ_V page- https://lnkd.in/gETRGQhT gitHub- https://lnkd.in/gy6SDTDS YouTube- https://lnkd.in/gUjdagq7 Insta- https://lnkd.in/gagfpvDj WhatsApp- https://lnkd.in/gjm7naaH WhatsApp https://lnkd.in/gbR-MrVy GoogleMap- https://lnkd.in/gFetgYvg JavaScript Mastery SRProSkillBridge doc Cred: Level Up Coding
I did not know which data base system you have evaluated. My article shows that a modern and advanced product is still declarative. One big problem with your execution order is, that if you and others believe that it is true, we get statements that is difficult to maintain. Writing Subquery as you mention in #2 is just 'terrible'. Etc.. So please tell about the product! https://www.garudax.id/posts/saastamoinen_execution-plan-for-several-statements-ugcPost-7431498012704538624-c601?utm_source=share&utm_medium=member_desktop&rcm=ACoAAAAXOpwBwbQBIp894FUaiep9FKebJdYxyUg