SQL & Databases Guide | Resources by Shumbul Arifa

🗄️ SQL & Databases

Almost every job touches a database. The good news: you only need a small slice of SQL to be genuinely useful. This guide teaches the queries you will actually write, with examples you can copy.

📋 Copy-ready queries 🔗 Joins made simple 🎯 Interview-ready

The one query shape to master

Most of SQL is variations on this. Learn the order and you can read almost anything:

SELECT column1, column2      -- which columns you want
FROM table_name              -- from which table
WHERE condition              -- filter rows
GROUP BY column1             -- bucket rows together
HAVING condition             -- filter those buckets
ORDER BY column2 DESC        -- sort the result
LIMIT 10;                    -- cap the rows

The database runs them roughly in the order FROM to WHERE to GROUP BY to HAVING to SELECT to ORDER BY to LIMIT, which is why you cannot use a SELECT alias in WHERE. Small detail, common interview gotcha.

Everyday queries you will actually write

Filtering and sorting:

SELECT name, salary
FROM employees
WHERE department = 'Engineering' AND salary > 50000
ORDER BY salary DESC;

Counting and grouping (how many employees per department):

SELECT department, COUNT(*) AS headcount
FROM employees
GROUP BY department
ORDER BY headcount DESC;

Aggregates (average salary per department, only where it beats 60k):

SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 60000;

Inserting, updating, deleting:

INSERT INTO employees (name, department, salary)
VALUES ('Asha', 'Engineering', 72000);

UPDATE employees SET salary = 80000 WHERE name = 'Asha';

DELETE FROM employees WHERE name = 'Asha';

Joins, the part everyone fears (they are simple)

A join combines rows from two tables using a shared column. Picture two tables, employees and departments, linked by a department id.

SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.id;
INNER JOIN

Only rows that match in both tables. The default and most common.

LEFT JOIN

All rows from the left table, plus matches from the right (nulls where none). Great for "who has no matching record?"

RIGHT JOIN

The mirror of LEFT, all rows from the right table. Rarely needed, you can flip the query instead.

FULL OUTER JOIN

Everything from both tables, matched where possible. Used less often day to day.

Interview favorite, find employees with no department:

SELECT e.name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id
WHERE d.id IS NULL;

Concepts interviews love

Practice tasks (do these)

Reading SQL is easy; writing it is the skill. Set up a free playground and try:

  1. Find the top 5 highest-paid employees.
  2. Count how many employees are in each department.
  3. List departments with an average salary above 60k.
  4. Join employees to departments and show each person's department name.
  5. Find employees who are not assigned to any department.
  6. Find the second-highest salary (a classic interview question).
-- Second highest salary, one clean way:
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

Which database should you learn?

DatabaseTypeGreat for
PostgreSQLSQL (relational)The best default. Powerful, free, loved by employers.
MySQLSQL (relational)Very common in web apps; similar skills to Postgres.
SQLiteSQL (file-based)Zero setup, perfect for learning and small apps.
MongoDBNoSQL (document)Flexible schemas, popular with Node/JS stacks.

Start with SQL (PostgreSQL or SQLite). The relational thinking transfers everywhere, and most jobs expect it.

Free places to practice

What to do next

🌱 New to SQL? Start calm

SQL reads almost like English: "select these columns from this table where this is true." You do not need to memorize everything, you need the handful of patterns below. Run them on a free playground (links at the end) as you read. Confused by a query? Paste it into ✦ Ask AI and ask it to explain line by line.