bhylu.com

Advertisements

SQL Syntax

A SQL statement is made from clauses that work together. Read a small statement in pieces before trying to memorise a long list of keywords. Clear spacing makes it easier to spot a missing condition or a misspelled column.

Understand the idea

SELECT names the result columns, FROM names the input table, and WHERE filters rows. SQL keywords are written in capitals here for readability; that is a style choice. Text values use single quotes. A semicolon ends the statement so another statement can follow. Table and column name case rules depend on the database and configuration.

Where to try it

Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.

SQLite sample data · MySQL / MariaDB sample data · See the sample tables

A worked example

SQLite

SELECT name, price_cents
FROM products
WHERE category = 'Stationery'
ORDER BY product_id;

Read the result

The query returns Pocket notebook at 250 cents and Pencil set at 450 cents. Both rows satisfy the category test. Products from other categories are excluded before the result is ordered.

Try one change

Change the category to Home, then deliberately misspell price_cents. Read the error and correct it.