If you're starting SQL for Data Analytics, don't try to memorize hundreds of queries. Focus on understanding how SQL thinks and practice consistently.
1. Master the basic SQL order
Learn these clauses first:
โข SELECT
โข FROM
โข WHERE
โข GROUP BY
โข HAVING
โข ORDER BY
โข LIMIT
Understand what each one does before moving to advanced SQL.
2. Understand the logical execution order
SQL doesn't logically execute a query in the same order you write it.
A simplified order is:
โข FROM
โข WHERE
โข GROUP BY
โข HAVING
โข SELECT
โข ORDER BY
โข LIMIT
This helps explain many SQL interview questions.
3. Get comfortable with filtering
Master:
โข WHERE
โข AND / OR / NOT
โข IN
โข BETWEEN
โข LIKE
โข IS NULL / IS NOT NULL
Note: use IS NULL, not = NULL.
4. Learn aggregate functions properly
You should be comfortable with:
โข COUNT()
โข SUM()
โข AVG()
โข MIN()
โข MAX()
Example:
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
5. Understand GROUP BY vs HAVING
โข WHERE โ filters rows before grouping
โข HAVING โ filters groups after aggregation
Example:
SELECT department, COUNT(*) AS employees
FROM employees
GROUP BY department
HAVING COUNT(*) > 10;
6. Master JOINs
For Data Analyst interviews, JOINs are extremely important. Learn:
โข INNER JOIN
โข LEFT JOIN
โข RIGHT JOIN
โข FULL OUTER JOIN
โข CROSS JOIN
โข SELF JOIN
Most importantly, understand why rows are included or excluded in each JOIN.
7. Always understand your keys
Know the difference between:
โข Primary Key
โข Foreign Key
โข Composite Key
โข Unique Key
Understanding relationships between tables will make JOINs much easier.
8. Don't ignore NULL
NULL does not mean:
โข 0
โข Empty string
โข False
Learn how NULL behaves with: IS NULL, IS NOT NULL, COALESCE(), NULLIF()
9. Learn CASE WHEN early
CASE is one of the most useful SQL features for analytics.
SELECT employee,
salary,
CASE
WHEN salary >= 100000 THEN 'High'
WHEN salary >= 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_category
FROM employees;
10. Practice subqueries
Understand queries inside queries:
SELECT *
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);
Then move toward correlated subqueries.
11. Learn CTEs
CTEs make complex SQL easier to read and maintain.
WITH sales_summary AS (
SELECT customer_id, SUM(amount) AS total_sales
FROM sales
GROUP BY customer_id
)
SELECT *
FROM sales_summary
WHERE total_sales > 10000;