Course curriculum
Tables and your first SELECT
Create a small practice table and ask for specific columns without changing stored data.
About 9 minutes · BeginnerThink in rows and columns
A table holds rows with named columns. A primary key identifies each row. SQL describes the result you want rather than a loop over each stored row.
These lessons use SQLite-compatible SQL. Create a disposable database using SQLite’s command-line shell or a local SQLite tool. Run the setup once; rerunning CREATE TABLE with the same name will fail.
Create the practice data
The students table contains three rows. Text values use single quotes, and each statement ends with a semicolon.
CREATE TABLE and INSERT change the practice database. The SELECT queries in subsequent lessons only read it.
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
score INTEGER NOT NULL
);
INSERT INTO students (id, name, score) VALUES
(1, 'Asha', 72),
(2, 'Ravi', 38),
(3, 'Meera', 85);Ask for named columns
SELECT chooses output columns; FROM names the table. Explicit columns keep your result predictable when the schema gains new fields.
Rows have no guaranteed order without ORDER BY. The query below requests a stable order using the primary key.
SELECT name, score
FROM students
ORDER BY id;Asha | 72 Ravi | 38 Meera | 85
Try it yourself
Select only the names from students, ordered by id.
Show a possible solution
SELECT name FROM students ORDER BY id;Keep exploring: official SQL documentation.