SELECT
Retrieve columns from a table.
Questions this answers
- →How do I get data out of a database?
- →How do I see all columns in a table?
- →How do I rename a column in my results?
- →How do I avoid duplicate rows?
How it works
Every SQL query starts with SELECT. It tells the database which columns you want back. You can select all columns with *, specific columns by name, computed values, or give any column a new name with AS.
Select all columns
SELECT * FROM artists;
💡 * means "all columns". Fine for exploring, but avoid it in production — adding a column to the table silently changes your results.
Select specific columns
SELECT name, genre, monthly_listeners FROM artists;
Rename a column with AS
SELECT name, monthly_listeners AS listeners FROM artists;
💡 AS gives the column a different name in your results. The original table is unchanged.
Remove duplicates with DISTINCT
SELECT DISTINCT genre FROM artists;
💡 DISTINCT removes duplicate rows from the result. Useful when you only care about unique values.