Tech & AI

SQL Basics: Query Any Database in 30 Minutes

SQL Basics: Query Any Database in 30 Minutes

The handful of SQL commands that handle most real work — explained without a computer science degree.

SQL is the language used to ask questions of data stored in a database. It has been standard for decades, it is readable, and a small subset of it covers the overwhelming majority of everyday tasks.

The mental model

Picture a table like a spreadsheet: rows are records, columns are fields. A customers table might have columns id, name, country and signup_date, with one row per customer.

SQL is how you select rows, choose columns, summarise groups and combine tables. That is essentially all of it.

Reading data

The core statement is SELECT.

SELECT name, country
FROM customers;

That returns two columns for every row. To narrow it down, add a condition with WHERE:

SELECT name
FROM customers
WHERE country = 'Egypt';

Useful conditions include =, <>, >, <, BETWEEN, LIKE (for text patterns) and IN (for a list of values). Combine them with AND, OR and NOT.

Sorting and limiting

SELECT name, signup_date
FROM customers
ORDER BY signup_date DESC
LIMIT 10;

ORDER BY sorts, DESC reverses it, and LIMIT returns only the first rows. This pattern — newest ten, top hundred — answers a surprising number of real questions.

Summarising

Aggregate functions collapse many rows into one number:

SELECT country, COUNT(*) AS customers
FROM customers
GROUP BY country
ORDER BY customers DESC;

GROUP BY defines the groups, and the aggregate — COUNT, SUM, AVG, MIN, MAX — produces a value for each. To filter the results rather than the rows, use HAVING:

SELECT country, COUNT(*) AS customers
FROM customers
GROUP BY country
HAVING COUNT(*) > 100;
WHERE filters rows before grouping; HAVING filters groups after.

Combining tables

Real data is spread across tables. JOIN brings them together:

SELECT c.name, o.total
FROM customers c
JOIN orders o ON o.customer_id = c.id;

A plain JOIN (an inner join) keeps only rows that match on both sides. A LEFT JOIN keeps every row from the first table, filling in blanks where there is no match — useful for finding customers with no orders.

Changing data

Three statements alter tables, and all three deserve respect:

  • INSERT INTO table (columns) VALUES (...) adds rows.
  • UPDATE table SET column = value WHERE condition changes rows.
  • DELETE FROM table WHERE condition removes rows.

⚠️ Always write the WHERE clause first. An UPDATE or DELETE without one affects every row in the table, and there is no undo.

Habits that prevent disasters

  • Select before you modify. Run the same conditions as a SELECT and check what you are about to affect.
  • Use transactions. Wrap changes in BEGIN and COMMIT, or roll back with ROLLBACK, so a partial change cannot survive.
  • Work on a copy first when you are unsure.
  • Read the numbers. If an update reports far more rows than expected, stop and investigate.

The bottom line

SELECT, WHERE, ORDER BY, LIMIT, GROUP BY, HAVING and JOIN are enough to answer most business questions. Learn those seven ideas and you can query almost any database.

Related articles

Practical Prompt Engineering for AI Tools

Practical Prompt Engineering for AI Tools

Better prompts are less about magic words and more about clear thinking. Here are the habits that reliably get more useful answers from AI tools.

📁 Tech & AI 🗓 September 30, 2026 ⏱ 8 min read
Using AI in Your Daily Work Without Losing Your Edge

Using AI in Your Daily Work Without Losing Your Edge

AI assistants can save real hours each week — if you use them for the right tasks. A practical guide to weaving them into everyday work.

📁 Tech & AI 🗓 October 1, 2026 ⏱ 8 min read
Cybersecurity Basics: Protecting Your Accounts and Devices

Cybersecurity Basics: Protecting Your Accounts and Devices

Most breaches do not start with brilliant hackers. They start with a reused password, an ignored update, or a link that should not have been clicked. Here is how to close those gaps.

📁 Tech & AI 🗓 October 2, 2026 ⏱ 8 min read

Suggested summaries

Tech & AI Homo Deus book cover

Homo Deus

Yuval Noah Harari · 2016
★★★★⯨ 4.5

Harari looks past famine, plague and war to ask what humanity will chase next: immortality, engineered happiness and god-like power over life itself.

Tech & AI
Tech & AI Life 3.0 book cover

Life 3.0

Max Tegmark · 2017
★★★★⯨ 4.5

Max Tegmark maps the choices ahead for artificial intelligence — utopia, catastrophe or something in between — and why values matter as much as code.

Tech & AI
Tech & AI The Pragmatic Programmer book cover

The Pragmatic Programmer

Andrew Hunt · 1999
★★★★★ 5

Hunt and Thomas distil decades of hard-won craft into practical habits: stay curious, keep code honest, automate the boring parts, and own your work.

Tech & AI