A SELECT statement names the columns to return, and FROM names the table to read them from. SELECT * returns every column, though naming columns explicitly is generally preferred in real code since it's clearer and more resilient to schema changes. Column and table aliases (AS) rename output columns or shorten long table references for readability.
SELECT specific columns, or everything with *
Naming columns explicitly is the idiomatic choice for real applications — SELECT * is convenient for quick exploration but can silently break code if the table's columns change later.
SELECT name, email FROM users; -- explicit columns, preferred
SELECT * FROM users; -- every column, convenient but fragileAliasing with AS
AS renames a column or table in the output, useful for computed columns, clarity, or shortening a long table name used repeatedly in a query.
SELECT
first_name AS name,
price * quantity AS total_cost
FROM orders AS o;DISTINCT: unique values only
DISTINCT removes duplicate rows from the result — applied across all selected columns together, not per-column.
SELECT DISTINCT country FROM customers;
-- returns each country name once, no matter how many customers share it