Skip to main content
Back to Documentation
DocsFundamentalsSELECT Statements

SELECT Statements

Fundamentals

Concept

The SELECT statement is the cornerstone of SQL. Every time you want to read data from a database you will write a SELECT. At its simplest it retrieves one or more columns from a single table, but it can also compute expressions, call functions, and combine data from many sources.

A basic SELECT has two required parts: the column list (what you want) and the FROM clause (where to get it). You can select all columns with the asterisk (*) shorthand, but in production code it is best practice to list columns explicitly so your queries remain predictable when the schema changes.

SELECT also supports computed columns and literal values. You can perform arithmetic, concatenate strings, and apply built-in functions directly in the column list, giving each result an alias for clarity.

Syntax

-- Select specific columns
SELECT column1, column2
FROM table_name;

-- Select all columns
SELECT * FROM table_name;

-- Computed columns with aliases
SELECT
  first_name,
  last_name,
  unit_price * quantity AS line_total
FROM order_items;

Practical Example

Using the ecommerce schema (customers, orders, order_items, products)

-- List every product with its computed sale price (10% off)
SELECT
  product_id,
  name,
  price,
  ROUND(price * 0.90, 2) AS sale_price
FROM products;

-- Combine first and last name for customer display
SELECT
  customer_id,
  first_name || ' ' || last_name AS full_name,
  email
FROM customers;

Common Pitfalls & Tips

  • 1Avoid SELECT * in application code — it fetches unnecessary data and breaks when columns are added or removed.
  • 2Remember that column aliases defined in SELECT cannot be used in the WHERE clause of the same query; the alias is resolved after filtering.
  • 3When mixing aggregate functions with non-aggregated columns you must add GROUP BY — otherwise the query will error.
Practice SELECT basics