Course curriculum
SQL · LESSON 1 OF 5

Tables and your first SELECT

Create a small practice table and ask for specific columns without changing stored data.

About 9 minutes · Beginner

Think 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.

SQL
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.

SQL
SELECT name, score
FROM students
ORDER BY id;
Expected output
Asha | 72
Ravi | 38
Meera | 85

Try it yourself

Select only the names from students, ordered by id.

Show a possible solution
SQL
SELECT name FROM students ORDER BY id;

Keep exploring: official SQL documentation.

0 of 5 completed on this device