SQL

One language for (almost) every database.

What is it?

SQL (Structured Query Language) is the language you use to talk to relational databases — MySQL, PostgreSQL, and SQLite all speak it, with only minor dialect differences. Data lives in tables (think spreadsheets: rows of records, columns of fields), and SQL is how you ask questions of it: "give me every order from this customer, newest first."

It's one of the best-value skills in software: learn it once and it transfers to virtually every database, every language, and every job — it has been the standard since the 1970s and isn't going anywhere.


When to use it

Whenever your app stores structured data — users, posts, orders, anything with consistent fields and relationships between records. That's the vast majority of applications. The main alternative, document databases like Firebase, trade SQL's strict structure and powerful queries for flexibility and real-time sync.


Core concepts
  • Tables, rows, columns — a users table has one row per user and columns like id, name, email. Each column has a type.
  • The big four statementsSELECT reads data, INSERT adds rows, UPDATE changes them, DELETE removes them. Most daily work is these four.
  • WHERE, ORDER BY, LIMIT — filter which rows you get, sort them, and cap how many come back.
  • Primary and foreign keys — every row gets a unique id; other tables reference it (orders.user_id) to model relationships.
  • JOINs — combine related tables in one query: every order together with the name of the user who placed it.

A taste of the code
-- Every order over $50, with the customer's name,
-- newest first
SELECT users.name, orders.total, orders.created_at
FROM orders
JOIN users ON users.id = orders.user_id
WHERE orders.total > 50
ORDER BY orders.created_at DESC
LIMIT 10;

SQL is declarative: you describe what you want, and the database figures out how to fetch it efficiently.


Your first steps
  1. Start with SQLite — it's a real SQL database with zero setup, perfect for practicing.
  2. Create a table and practice the big four: INSERT a few rows, SELECT them back, UPDATE one, DELETE one.
  3. Add WHERE, ORDER BY, and aggregate functions (COUNT, SUM, GROUP BY) to your queries.
  4. Model a two-table relationship — users and their posts — and write your first JOIN.
  5. Use it from code: connect from Python, PHP, or Node.js, always with prepared statements (never paste user input into a query string).

← Back to Stack Picker All primers