Blog / Build with AI /
SQL basics for builders, learned with AI
Spreadsheets are brilliant until they aren’t. Somewhere around 50,000 rows, with three tabs of lookups and a formula nobody dares touch, you start wondering whether there’s a better way to ask questions of your data.
There is, and it’s called SQL. It’s older than most of the tools you use, it’s still everywhere, and it’s one of the easiest things to learn with an AI tutor beside you. You don’t need to become a database engineer. A handful of commands will answer most of the questions a website owner, shop manager or small builder actually asks.
What SQL is
SQL (Structured Query Language) is a way of asking a database questions in something close to plain English.
A database is a set of tables, which look like spreadsheet tabs: rows of records, columns of fields. SQL lets you say “show me these columns, from this table, where this is true, sorted like this”. WordPress stores your posts and settings in a database. Many shops and tools do the same. Knowing a little SQL lets you look inside.
Why learn it with AI
AI is a patient tutor for SQL because:
- The language is small and very regular.
- The feedback is instant: run the query, see the result.
- You can ask it to explain any query line by line.
- It can translate a plain-English question into a query, which you then learn to read.
The trap is trusting generated queries blindly. A query that runs isn’t necessarily a query that answers your question. That’s why we learn the basics rather than just copy-pasting.
A practice table to imagine
Say you have a table called products:
| id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Desk lamp | Lighting | 18.00 | 40 |
| 2 | Floor lamp | Lighting | 55.00 | 0 |
| 3 | Notebook | Stationery | 4.50 | 200 |
| 4 | Pen set | Stationery | 9.00 | 75 |
(Made-up data. Nothing here is a real shop.)
You can practise on free tools that run a small database in your browser or on your computer; ask AI to set up the table above with an INSERT script and you’re ready.
The five commands that do most of the work
1. SELECT and FROM: choose columns and a table
SELECT name, price FROM products;
“Show me the name and price from products.” Use SELECT * to show every column, and then stop using it as soon as you can, because naming columns is clearer.
2. WHERE: filter rows
SELECT name, stock FROM products WHERE stock = 0;
This lists out-of-stock items. You can combine conditions with AND and OR, and compare with <, >, <=, >= and <> (not equal).
3. ORDER BY and LIMIT: sort and trim
SELECT name, price FROM products ORDER BY price DESC LIMIT 3;
The three most expensive products. DESC means high to low; leave it off or use ASC for low to high.
4. GROUP BY: summarise
SELECT category, COUNT(*) AS items, AVG(price) AS average_price
FROM products
GROUP BY category;
One row per category, with how many items it has and the average price. COUNT, SUM, AVG, MIN and MAX are the workhorses. AS gives a column a friendlier name.
5. JOIN: combine tables
Real databases split information across tables. Say you also have costs, with product_id and unit_cost:
SELECT p.name, p.price, c.unit_cost, p.price - c.unit_cost AS margin
FROM products p
JOIN costs c ON c.product_id = p.id;
The ON line says which columns match. That’s the whole idea of a join: line up rows from two tables by a shared value. Joins are the part people find hardest, and the part worth asking AI to draw as a diagram.
A learning routine that works
Think of it as advice for any beginner:
- Ask the question in English first. “Which categories have more than one product?”
- Write your own attempt, even if it’s wrong.
- Ask AI to compare your attempt with its own and explain the difference.
- Run both and check the results are the same.
- Change one thing and predict the result before running it.
That fourth step builds a useful instinct: two different queries can both look right and give different answers. Prediction is the skill; typing is the easy part.
Prompts that help
I’m learning SQL. Here’s my table (paste CREATE TABLE). Give me five practice questions of increasing difficulty. Don’t show answers yet.
Here’s my query and the result I expected. Explain why the output is different, in plain English.
Explain this query one clause at a time. Then rewrite it so a beginner could read it.
Tell the AI which database you use. SQLite, MySQL, PostgreSQL and SQL Server share most basics but differ in small ways (date functions especially).
Danger zone: reading versus changing
SELECT only looks. Other commands change things:
UPDATEedits rows.DELETEremoves rows.DROPremoves a whole table.
If you ever run SQL on a database that matters, such as a live site, take a backup first and run a SELECT with the same WHERE before you UPDATE or DELETE, to see which rows would be affected. A missing WHERE on an UPDATE changes every row. It’s the classic beginner disaster, and it’s entirely avoidable. Backups as security: the last line of defence makes the case for backups well.
Also, never paste real customer data into an AI chat. Use made-up rows or a sample.
Where it helps site and shop owners
- Finding things in WordPress: how many posts have a given status, which posts use a certain shortcode.
- Product data: stock below a threshold, products missing a field, price and cost side by side.
- Reports: counts and totals by month or category without wrestling a pivot table.
- Cleaning up after imports, once you’re careful enough to preview changes.
SQL also pairs nicely with the other skills in this series. Results can be exported as CSV and, with a script, as JSON, which is where JSON explained for non-developers comes in.
Key takeaways
- SQL asks questions of tables using a few regular commands.
- Learn SELECT, WHERE, ORDER BY, GROUP BY and JOIN first.
- Predict a result before you run the query.
- Preview with SELECT before any UPDATE or DELETE, and back up first.
- Practise on made-up data.
FAQ
Do I need a database server to practise?
No. Free tools can run a small database on your own computer or in a browser.
Is SQL still worth learning with AI around?
Yes. You still need to read what the AI wrote and judge whether it answers your question.
Which database should I start with?
Whichever one you’ll meet in real life. For WordPress that’s MySQL or MariaDB; for experimenting, SQLite is the lightest.
Related reading
What’s one question about your data that a spreadsheet makes painful? Turn it into a SELECT.