SQL Query Order of Execution
SQL Query Order of Execution
SQL - (Structured Query Language ) is the most wanted tool for everyone who is living in IT Industry ,it like breathing air and water -this both can be like EXCEL & SQL without this 2 we can't do any projects.
Lets learn about Order of Execution in SQL
Why the order of SQL is Important ?
Each and every task there will be an ORDER to reach like
If we want to land in GOOD IT JOB with the proper role as Business Analyst or Data Analyst
should be good to have an education criteria with IT KINGS- EXCEL , SQL , POWERBI / TABLEAU / MICRO STRATEGY / STATISTICS / STORY TELLING (communication).
As like this same way there will be an ORDER in SQL queries
SQL Query Order of Execution
Why Order of Execution is Important ?
- Helps to understand the concept easily
- Can able to debug query without confusion
- It optimizes the SQL query results
- It reduce the amount of data to run in DB and run faster without any hassle
What is the ORDER to execute query in SQL ?
The order of Execution is determined by the logical queries and processing phase with the below list of clauses.
Order | Clause | Statement |
1 | FROM & JOIN | Helps to find and join the data |
2 | WHERE | Filter data from the bunch to get exact result |
3 | GROUPBY | From the bunch of data will get single result |
4 | HAVING | It applies to the grouped rows |
5 | SELECT | Determine the column which needs to be select from data |
6 | DISTINCT | Helps to remove DUPLICATES |
7 | ORDER BY | Order data by sorting Ascending / Descending order |
8 | LIMIT | Restrict the number of rows to show on top of the results |
- FROM & JOIN
- Very first query ( clause ) starting here
- It specifies the tables and views from where the data going to retrieve
- It decides which DML operation is going to run
- FROM - is evaluating first query
- JOIN - merge both table to get the proper result
- WHERE
- Filter the rows which returned by FROM clause based on the condition
- Able to find the exact data with WHERE clause
- GROUPBY
- Group the unstructured data to get exact results
- Aggregate function - SUM,MIN,MAX...etc. are the main functions will be used in GROUP BY results
- HAVING
- It filtered the grouped results
- Same like WHERE clause but it should apply after GROUP BY Clause
- SELECT
- What exact column needs to be select to get the proper data will be finalize in SELECT statement
- It helps to get appropriate results for all the queries
- DISTINCT
- Rows with the duplicates will be eliminated
- Helps to get the exact results from the data
- ORDER BY
- Ordering data with the expecting format
- Sorting data by Ascending or descending order to view the highest / lowest outcome
- LIMIT
- Limits the data what needs to be shown on top of the results
- Helps while performing large data sets
Note 🔖 This order of execution is the basic but it will differ for Sub-queries, windows functions ..etc.
Please Follow , Like , Share and Comment to get the valuable insights related to DATA ANALYST / BUSINESS ANALYST related topics.
@Thanasevi C
Comments
Post a Comment