SQL Tutorial for Beginners: Real Queries for Real Jobs
Every analyst, every backend developer, every data engineer writes SQL. This tutorial walks you from your first SELECT to window functions in one sitting, using a single example schema you can keep in your head.
01.Our example schema
Imagine an online store with three tables. We'll use this throughout.
customers(id, name, city)
orders(id, customer_id, total, created_at)
order_items(id, order_id, product, qty, price)02.SELECT, WHERE, ORDER BY
The three clauses cover the majority of analyst queries. Always reach for `LIMIT` when you're exploring a new table — production databases punish people who forget.
SELECT name, city
FROM customers
WHERE city = 'Chennai'
ORDER BY name
LIMIT 50;03.JOINs without the confusion
INNER JOIN keeps only matches. LEFT JOIN keeps everything from the left table. RIGHT JOIN is rarely used in practice — flip the tables and use LEFT instead.
SELECT c.name, COUNT(o.id) AS order_count
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.name
ORDER BY order_count DESC;04.GROUP BY and aggregates
SUM, COUNT, AVG, MIN, MAX. Always include every non-aggregated column in GROUP BY. PostgreSQL will refuse to run the query otherwise — that's a feature, not a bug.
05.Window functions for ranking
Window functions compute a value across a set of rows without collapsing them. Useful for ranking, running totals and de-duplication.
SELECT id, customer_id, total,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY created_at DESC) AS recency
FROM orders;06.EXPLAIN: read the query plan
When a query is slow, prefix it with `EXPLAIN ANALYZE`. Look for `Seq Scan` on big tables (usually bad) and missing indexes. Adding the right index is often a 100x speedup.
Take Databases from tutorial to job offer.
Our Databases programs come with projects, mentor reviews and 100% placement support.
Read next
Java Tutorial
A structured, text-only Java tutorial covering core syntax, OOP, collections, streams and a first Spring Boot REST API — written for absolute beginners aiming at developer roles.
Python Tutorial
Learn Python the way working developers use it — from syntax and data structures to virtual environments, requests and a first Flask API. Text-only, runnable code, zero filler.
AWS Tutorial
Understand AWS the way a working cloud engineer does. Covers IAM, EC2, S3, VPC basics, plus your first three-tier deployment and a cost-safety checklist.
