SELECT

Basic SQL
≈ 1 min read

SELECT reads data

SELECT builds a result from database data. In the simplest form, we specify which columns we want and which table they should come from.

SELECT id, name, email
FROM users;

You can think of the query result as a new temporary table: it has the selected columns and the rows returned by the database. A normal SELECT does not modify the source table.

You do not have to select every column

SELECT * selects every available column, but application code often benefits from listing only the columns that are actually needed. That makes the expected result clearer and reduces dependence on accidental changes to the table structure.

SELECT name AS user_name
FROM users;

With AS, a result column can be given an alias. The alias changes the name in the query result, not the column name in the table itself.