# SQL Fundamentals

> Query and change relational data with SELECT, JOIN, GROUP BY, INSERT, UPDATE and DELETE, and understand transactions. Free notes, key concepts, resources and a...

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

Query and change relational data with SELECT, JOIN, GROUP BY, INSERT, UPDATE and DELETE, and understand transactions.

Beginner · about 10 hours · difficulty 2/5

An ORM writes SQL for you, but you still need to read and reason about SQL to model data, debug slow queries and pass technical interviews. Most placement tests include SQL questions.

### Reading data

- SELECT with WHERE, ORDER BY, LIMIT and OFFSET.
- **JOINs**: INNER JOIN for matching rows, LEFT JOIN to keep rows with no match (students with zero applications).
- **Aggregation**: COUNT, SUM, AVG with GROUP BY and HAVING ("companies with more than 10 applicants").
- Subqueries and **CTEs** (WITH) to break complex queries into steps.

### Changing data

INSERT, UPDATE and DELETE, always with a WHERE clause on updates and deletes. Use RETURNING in PostgreSQL to get the changed rows back.

### Transactions

Group statements that must succeed or fail together (create an order and reduce stock) with BEGIN and COMMIT. Learn the ACID properties at a high level.

### Practice setup

Install PostgreSQL locally or with Docker, or use a free hosted database, and connect with psql or a GUI like pgAdmin or DBeaver.

### Pitfalls

- UPDATE without WHERE.
- Building SQL by concatenating strings with user input, which causes SQL injection. Always use parameterised queries.
- Using SELECT \* everywhere in application code.

You are ready to move on when you can write a query that lists each company with its number of applicants and average applicant CGPA, including companies with zero applicants.

## Key concepts

- **SELECT, WHERE, ORDER BY**
- **INNER and LEFT JOIN**
- **GROUP BY and aggregates**
- **INSERT, UPDATE, DELETE**
- **Subqueries and CTEs**
- **Transactions and ACID**
- **Parameterised queries**
- **Window functions**

## Mini project

Create a students, companies and applications schema in PostgreSQL, load 100 rows of sample data, and write 15 queries answering placement-cell questions such as top recruiters, branch-wise placement rate and average CTC.

## Check yourself

Why does an INNER JOIN between companies and applications drop companies with no applicants, and how do you keep them?

## Free resources

- [PostgreSQL Tutorial](https://www.postgresql.org/docs/current/tutorial.html) (PostgreSQL)
- [SQLBolt interactive lessons](https://sqlbolt.com/) (SQLBolt)
- [SQL tutorial](https://www.w3schools.com/sql/) (W3Schools)

Previous: [Error Handling, Validation and API Hardening](https://www.internhack.in/roadmaps/tracks/full-stack/api-errors-and-validation) · Next: [Relational Data Modelling in PostgreSQL](https://www.internhack.in/roadmaps/tracks/full-stack/postgres-data-modeling)

## More in PostgreSQL and Data Access

- [SQL Fundamentals](https://www.internhack.in/roadmaps/tracks/full-stack/sql-basics)
- [Relational Data Modelling in PostgreSQL](https://www.internhack.in/roadmaps/tracks/full-stack/postgres-data-modeling)
- [Prisma ORM and Migrations](https://www.internhack.in/roadmaps/tracks/full-stack/prisma)
- [Drizzle ORM and Migrations](https://www.internhack.in/roadmaps/tracks/full-stack/drizzle)
- [Indexes and Query Performance](https://www.internhack.in/roadmaps/tracks/full-stack/indexes-and-query-performance)
- [Caching with Redis](https://www.internhack.in/roadmaps/tracks/full-stack/redis-caching)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
