TetSharing
SQL tutorial · 14 chapters
  1. Get started
  2. SELECT columns
  3. WHERE filters
  4. AND, OR, NOT, IN, BETWEEN
  5. ORDER BY and LIMIT
  6. LIKE patterns
  7. NULL values
  8. COUNT, SUM, AVG, MIN, MAX
  9. GROUP BY and HAVING
  10. INNER JOIN
  11. LEFT JOIN
  12. Subqueries
  13. INSERT, UPDATE, DELETE
  14. CREATE TABLE and constraints

Final SQL quiz
Cheat sheet: sql cheat sheet

Chapter 1 of 14 · By Ethan Cole · Updated November 21, 2026

SQL Tutorial for Beginners: Your First Query

SQL (Structured Query Language, pronounced "ess-cue-ell" or "sequel") is the language for asking questions of relational databases. Banks, online shops, phone apps and analytics tools all keep their data in tables and use SQL to read and change it. It is one of the most durable skills in tech: queries written decades ago still run today.

Tables, rows and columns

A relational database stores data in tables. Each table describes one kind of thing, such as authors, and has a fixed set of named columns like name and country. Each row is one record: one author. Every row in our authors table has an id, a whole number that uniquely identifies it, called the primary key. Other tables refer to authors by that id, which is how tables are linked.

The sample database for this track is a small, fictional bookstore with five tables:

  • authors (id, name, country, born)
  • books (id, title, author_id, genre, price, year, stock)
  • customers (id, name, city, email, joined)
  • orders (id, customer_id, ordered_on)
  • order_items (order_id, book_id, qty)

Your first query

SELECT * FROM authors; means "give me every column (*) of every row in the authors table". Press Run to execute it. The first time, your browser loads SQLite compiled to WebAssembly and builds the sample database in memory; nothing is sent to a server.

SQLite · editable

Expected output

id | name | country | born
1 | Maya Lindqvist | Sweden | 1974
2 | Daniel Okafor | Nigeria | 1981
3 | Rosa Delgado | Mexico | 1968
4 | Tom Becker | USA | 1990
5 | Aiko Tanaka | Japan | 1985

The expected output shows the result in the plain text format of the sqlite3 command-line tool: a header line with column names, then one line per row, with values separated by |. The runner shows the same result as a table.

How SQL reads

SQL is declarative: you describe the result you want, and the database works out how to get it. Keywords such as SELECT and FROM are not case-sensitive, but writing them in capitals is a strong convention that makes queries easy to scan. Table and column names are usually lowercase. A semicolon ends each statement, and -- starts a comment that runs to the end of the line.

Common mistakes

  • Misspelling a table name, which gives no such table.
  • Using double quotes for text. In SQL, text values use single quotes: 'Sweden'. Double quotes are for identifiers such as column names.
  • Forgetting the semicolon between two statements.

Summary

  • Relational data lives in tables of rows and columns.
  • SELECT * FROM table; returns every column of every row.
  • Keywords are written in capitals by convention; text values use single quotes.

Quiz: Get started

1. In SELECT * FROM authors;, what does * mean?

* selects every column of the table.

2. What is a primary key?

A primary key such as id gives every row a unique identity.

3. How are text values written in SQL?

Standard SQL uses single quotes for strings.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.