SELECT Basics
Retrieve rows and columns from a table
Skills taught: sql.select, sql.from, sql.column-alias, sql.distinct, sql.limit
The SELECT statement
-- Get all columns from all rows
SELECT * FROM users;
-- Get specific columns
SELECT name, city FROM users;
-- Rename columns with aliases
SELECT name AS full_name, email AS contact FROM users;
-- Calculated columns
SELECT name, price, stock, price * stock AS inventory_value
FROM products;
-- Unique values only
SELECT DISTINCT city FROM users;
-- Limit number of rows
SELECT * FROM products LIMIT 3;
-- Expressions without a table
SELECT 2 + 2 AS sum, 'SQL' AS language, UPPER('hello') AS greeting;
Frequently Asked Questions
Is SQL case-sensitive?
SQL keywords (SELECT, FROM, WHERE) are case-insensitive — SELECT, select, and Select are the same. Column and table names follow the database's rules — usually case-insensitive but best to match the exact case you created them with. String comparisons can be case-sensitive depending on the database's collation.
What is the difference between AS and no alias?
Without AS, the column in the output keeps its original name (or the expression text). With AS alias, the output column gets the alias name. Aliases make results more readable and are required for calculated columns. They're also how you reference aggregated columns in ORDER BY.