beginner
SELECT Statement
5 min read
The SELECT statement is the core building block of Data Query Language (DQL). It tells the database engine which columns and computed values to retrieve from one or more tables.
1. Basic Syntax
sql
SELECT column1, column2, column3
FROM table_name;
2. Selecting All Columns (SELECT *)
The asterisk * acts as a wildcard to select all available columns in a table:
sql
SELECT *
FROM employees;
Best Practice Warning
In production systems, avoid SELECT *. Always explicitly list the required column names to reduce I/O network payload, improve caching, and protect against schema migration bugs.
3. Column Aliases (AS)
You can rename result set headers using the AS keyword:
sql
SELECT
first_name AS given_name,
salary * 12 AS annual_compensation
FROM employees;
4. Calculated & Constant Columns
SQL allows performing mathematical operations and literal projections inside SELECT:
sql
SELECT
product_name,
unit_price,
unit_price * 0.9 AS discounted_price,
'Active Catalog' AS status
FROM products;