# SQL Fundamentals

> Query relational data with SELECT, WHERE, GROUP BY, HAVING, ORDER BY and joins, and understand how NULLs and data types behave. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/data-engineer/sql-basics
Last updated: 2026-11-28

Query relational data with SELECT, WHERE, GROUP BY, HAVING, ORDER BY and joins, and understand how NULLs and data types behave.

Beginner · about 12 hours · difficulty 2/5

SQL is how you talk to databases and warehouses. Every data engineer interview in India starts with SQL, and most of your daily work ends in it.

### The core query

- `SELECT` columns and expressions, `FROM` a table, `WHERE` to filter rows.
- `GROUP BY` with aggregates (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`), `HAVING` to filter groups.
- `ORDER BY` and `LIMIT`.
- Learn the **logical order**: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT. It explains why you cannot use a SELECT alias in WHERE.

### Joins

- `INNER`, `LEFT`, `RIGHT`, `FULL OUTER` and `CROSS` joins.
- Joining on the right key: an order table joined to a payments table on `order_id` can multiply rows if an order has several payment attempts.
- Anti-joins (`LEFT JOIN ... WHERE right.id IS NULL` or `NOT EXISTS`) to find missing records.

### NULLs and types

- `NULL` means unknown. `NULL = NULL` is not true; use `IS NULL`. `COUNT(col)` skips NULLs, `COUNT(*)` does not.
- Use `COALESCE` deliberately and know types: integers vs decimals for money, `DATE` vs `TIMESTAMP`, text.

### DDL and DML

`CREATE TABLE`, `INSERT`, `UPDATE`, `DELETE`, primary and foreign keys. Practise on PostgreSQL locally or in Docker.

### Pitfalls

- Using `DISTINCT` to hide a join that duplicated rows instead of fixing the join.
- Filtering a LEFT JOIN's right table in WHERE, which silently turns it into an INNER JOIN.
- Storing money as floats.

You are ready to move on when you can write, without help, a query returning each city's order count and revenue for last month, including cities with zero orders.

## Key concepts

- **SELECT, WHERE, ORDER BY, LIMIT**
- **GROUP BY and HAVING**
- **Logical query order**
- **Inner, left, full and cross joins**
- **Anti-joins and semi-joins**
- **NULL semantics**
- **Data types for money and time**
- **DDL and DML**

## Mini project

Load a sample e-commerce dataset into PostgreSQL. Write 15 queries of increasing difficulty: filters, aggregates, each join type, and an anti-join that finds customers who never ordered.

## Check yourself

Why does a LEFT JOIN followed by WHERE payments.status = 'success' drop orders with no payments, and how do you fix it?

## Free resources

- [SQLBolt interactive lessons](https://sqlbolt.com/) (SQLBolt)
- [PostgreSQL tutorial](https://www.postgresql.org/docs/current/tutorial.html) (PostgreSQL)
- [SQL roadmap](https://roadmap.sh/sql) (roadmap.sh)
- [Mode SQL tutorial](https://mode.com/sql-tutorial/) (Mode)

Previous: [Production-Grade Python](https://www.internhack.in/roadmaps/tracks/data-engineer/python-production) · Next: [Advanced SQL: CTEs, Subqueries and Set Logic](https://www.internhack.in/roadmaps/tracks/data-engineer/advanced-sql)

## More in SQL for Data Engineering

- [SQL Fundamentals](https://www.internhack.in/roadmaps/tracks/data-engineer/sql-basics)
- [Advanced SQL: CTEs, Subqueries and Set Logic](https://www.internhack.in/roadmaps/tracks/data-engineer/advanced-sql)
- [Window Functions](https://www.internhack.in/roadmaps/tracks/data-engineer/window-functions)
- [Query Plans, Indexes and Performance](https://www.internhack.in/roadmaps/tracks/data-engineer/query-plans)
- [Transactional Databases as Sources](https://www.internhack.in/roadmaps/tracks/data-engineer/oltp-databases)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/data-engineer)
