SQL order of query execution

The order in which the various SQL statements appear in a query is as follows:

  1. SELECT
  2. FROM
  3. [JOIN]
  4. WHERE
  5. GROUP BY
  6. HAVING
  7. WINDOW
  8. ORDER BY

ome of the important points that you should keep in mind while writing a query are as follows:

  • Use inner joins wherever possible to avoid having any unnecessary rows in the resultant table.
  • Apply all the required filters to get only the required data values from multiple tables.
  • Index the columns that are frequently used in the WHERE clause.
  • Avoid using DISTINCT while using the GROUP BY clause, as it slows down query processing.
  • Avoid using SELECT * as much as possible. Select only the required columns.
  • Use the ORDER BY clause only if it is absolutely necessary, as it is processed late in a query.
  • Avoid using LIMIT and OFFSET as much as possible. Instead, apply appropriate filters using the WHERE clause.

--

--

--

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Become a more productive developer!

HOW IT ALL STARTED — My journey to the Azubi re/Start Program

Part 4 - Setting Up Git Server (GitLab)

7 Chrome DevTools Shortcuts to Boost Your Productivity

What are the differences between Envoy, HAProxy, & Nginx?

Ansible Basics in 5 Minutes

The New Material Buttons Version 1.22 in Flutter

Granular Control of “R” Shiny apps with Docker containers and ShinyProxy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TechGuy

TechGuy

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer

More from Medium

Introduction to SQL

Fig : Relational Database Design (source : researchgate.net)

Go nulls and SQL

REGEX in SQL