Member-only story
Don’t Start Your SQL Queries with the ‘Select’ Statement
Follow this right approach to write your SQL queries
The Problem
The majority of developers start writing their SQL queries with the ‘SELECT’ clause, then write ‘FROM’, ‘WHERE’, ‘HAVING’….and so on. But this is not the ‘right’ way of writing your SQL queries as this is very prone to syntactic errors, especially if you are a beginner in SQL.
The Solution
The ‘ideal’ query writing sequence should be in line with how the SQL executor executes the queries. This will ensure that you don’t commit any syntactic errors and write efficient SQL queries. You will know how to filter data before performing join, when to use ‘HAVING’ or ‘WHERE’ clause and more.
In this blog post, we will look at the ‘ideal’ way of writing a SQL query that will help you become an efficient SQL developer.
We will be using the Customer and Order tables (below) to find the top 2 customers from the USA/UK who have a total spend of more than $300.