SQL Query Order of Execution

                                                 SQL Query Order of Execution


SQL

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

  1. FROM & JOIN
    1. Very first query ( clause ) starting here
    2. It specifies the tables and views from where the data going to retrieve
    3. It decides which DML operation is going to run
      1. FROM - is evaluating first query
      2. JOIN - merge both table to get the proper result
  2. WHERE
    1. Filter the rows which returned by FROM clause based on the condition
    2. Able to find the exact data with WHERE clause
  3. GROUPBY
    1. Group the unstructured data to get exact results
    2. Aggregate function - SUM,MIN,MAX...etc. are the main functions will be used in GROUP BY results
  4. HAVING
    1. It filtered the grouped results
    2. Same like WHERE clause but it should apply after GROUP BY Clause
  5. SELECT
    1. What exact column needs to be select to get the proper data will be finalize in SELECT statement
    2. It helps to get appropriate results for all the queries
  6. DISTINCT
    1. Rows with the duplicates will be eliminated
    2. Helps to get the exact results from the data
  7. ORDER BY
    1. Ordering data with the expecting format
    2. Sorting data by Ascending or descending order to view the highest / lowest outcome
  8. LIMIT
    1. Limits the data what needs to be shown on top of the results
    2. 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

Popular posts from this blog

SQL Case Study Finance Analysis

A Day in the Life of a Data Analyst Interviewee