SQSQL · Lesson 1 of 8

Tables & SELECT

A relational database is just spreadsheets with rules: tables made of rows and columns. SELECT is how you ask questions about them — and it's 80% of the SQL you'll ever write.

Everything in SQL revolves around tables. A table has named columns (each with a type) and any number of rows. SELECT reads rows out of a table. You choose which columns you want, and optionally filter which rows come back.

SQL
-- A table called 'students' might look like:
-- id | name    | age | grade
-- 1  | Ada     | 17  | 95
-- 2  | Linus   | 16  | 88
-- 3  | Grace   | 17  | 92

-- Get every column of every row:
SELECT * FROM students;

-- Get only some columns:
SELECT name, grade FROM students;

-- Rename a column in the output with AS:
SELECT name, grade AS score FROM students;
◆ Note
SQL keywords are case-insensitive — select, SELECT, and SeLeCt all work. Convention is UPPERCASE for keywords and lowercase for table/column names, which makes queries easier to scan.
SQL
-- Filter rows with WHERE:
SELECT name FROM students WHERE age = 17;

-- Comparison operators: =, <>, <, >, <=, >=
SELECT name FROM students WHERE grade >= 90;

-- Combine conditions with AND / OR / NOT:
SELECT name FROM students
WHERE age = 17 AND grade > 90;

-- Pattern matching with LIKE (% = any characters):
SELECT name FROM students WHERE name LIKE 'A%';
✦ Tip
Note the 'not equal' operator is <> in standard SQL, though most databases also accept !=. Also: SQL strings use single quotes ('Ada'), not double quotes — double quotes mean identifiers (column/table names) in standard SQL.