CodeMIRAI
0 XP

SELECT

2 min read 6 runnable examples Quiz included

SELECT is how you read data. Every query you write starts here.

All columns

SQL
SELECT * FROM products;

* means "every column". It's handy for exploring a table, but in real code it's better to name the columns you need.

Choosing columns

List the columns you want, separated by commas, in the order you want them:

SQL
SELECT name, price
FROM products;

Calculated columns

A SELECT can compute new values from existing columns:

SQL
SELECT name, price, price * 1.18 AS price_with_tax
FROM products;

AS gives the new column a readable name, called an alias.

Rounding

SQL
SELECT name, ROUND(price * 1.18, 2) AS price_with_tax
FROM products;

Joining text

In SQLite, || joins text together:

SQL
SELECT first_name || ' ' || last_name AS full_name, title
FROM employees;

Literal values and expressions

A SELECT doesn't even need a table:

SQL
SELECT 2 + 3 AS answer, 'Hello, SQL' AS greeting, DATE('now') AS today;
Finished this lesson?Mark it complete to earn +20 XP and move your progress on.