SQL basics: ask your database questions
Read SELECT queries, filter and count, understand INSERT, UPDATE and DELETE, and run AI-written SQL safely.
What SQL is
SQL is the language for asking a database questions and changing its data. Supabase uses Postgres, which speaks SQL. AI will happily write SQL for you, but you should be able to read it, because one wrong line can change every row in a table.
Reading data
SELECT name, email FROM signups WHERE interest = 'coding' ORDER BY created_at DESC LIMIT 10; reads as: show the name and email from the signups table, only rows where interest is coding, newest first, ten at most. COUNT(*) counts rows, GROUP BY interest counts per group, and JOIN combines tables that share an id (for example, orders with the customers who placed them).
Changing data, carefully
- INSERT INTO adds rows; UPDATE ... SET changes them; DELETE FROM removes them.
- UPDATE and DELETE without a WHERE change or delete every row in the table.
- Before running one, run a SELECT with the same WHERE to see exactly which rows it will touch.
- Make sure a backup exists, and try risky changes on a copy or a branch first.
- Schema changes (new tables or columns) belong in migrations, so every environment stays in step.
Run SQL safely
In your app, never build SQL by pasting user input into a string; use parameters or your library's query builder to prevent SQL injection. Row level security protects data when your app queries it, but a database dashboard's SQL editor usually runs with full admin rights, so treat it like a power tool. Ask your AI helper to explain each line before you press run.
Key terms
- SQL
- The language for asking a database questions and changing it.
- Postgres (PostgreSQL)
- A trusted open-source SQL database. Supabase is built on it.
- Table
- One kind of thing in a database, like users or orders.
- Row
- One item in a table, like one user.
- Column
- One detail stored for every row, like email.
- JOIN (SQL)
- Combines rows from two tables that share a value, like orders and the customers who placed them.
- Migration
- A saved, ordered script that changes the database structure.
- Row level security (RLS)
- Database rules that decide which rows each user may read or change.
Try it
Your first queries
- In a practice project's SQL editor, create a small table of sign-ups with five fake rows (ask AI for the INSERT statements).
- Write a SELECT that shows only one interest, newest first.
- Count sign-ups per interest with GROUP BY.
- Write an UPDATE with a WHERE, but first run the matching SELECT to check which rows it would change.
Ask an AI tutor about this guide
Copy a prompt into ChatGPT, Claude or Gemini to go deeper. Check what it tells you against the guide.
- Explain it like I'm 12
- Quiz me (5 questions, one at a time)
- Show me a real example for my situation
- What do beginners get wrong?
Knowledge check
Five questions. Get 4 right to earn the Query Writer badge. You can retake it as often as you like.
Question 1 of 5
Finished the How software works guides? Take the How software works track test for ten mixed questions.
My notes
Write what clicked, what confused you, and what you want to try. Saved in this browser only.
Learn it live
Digital Builders University runs small live workshops where you build something real with an instructor beside you, starting with Vibe Coding 101.
See workshopsPractise it
- Cheat sheet: SQL
- Game: Code Scramble (put the lines of a working program back in order)
- Game: Query Quest (pick the SQL that answers the question)
- Game: Bug Hunt (read short code snippets and find the bug)
Official sites
Last reviewed November 25, 2026. AI tools change fast; check each tool’s own site for current features, plans and prices.
