pbPassingBI
/
Foundations & querying beginner 5 min

The SELECT statement

Choosing columns, renaming them, and the difference between * and naming them.

What you'll be able to do
  • Write a basic SELECT
  • Rename output columns with AS
  • Explain why SELECT * is discouraged

Selecting columns

SELECT customer_id, name, city
FROM customers;

The SELECT clause lists the columns you want; FROM names the table. Column order in the output follows the order you write them, not the table's.

SELECT *

SELECT * returns every column:

SELECT * FROM customers;

Fine for exploring. Poor in anything you save, for three reasons: it moves more data than you need, it breaks silently when someone adds or reorders columns, and it hides your intent from the next reader.

Name the columns in anything that will run more than once.

Renaming with AS

SELECT name AS customer_name,
       total AS order_total
FROM orders;

AS is optional in most dialects — total order_total works — but including it is clearer.

Use double quotes for aliases containing spaces or reserved words: AS "Order Total". Note single quotes are for string values, not identifiers.

Expressions in SELECT

You are not limited to columns:

SELECT name,
       price * quantity AS revenue,
       UPPER(city) AS city_upper
FROM order_lines;

An expression without an alias gets a database-generated name, which is rarely useful. Alias anything computed.

Key points
  • Name your columns rather than using SELECT * in saved queries
  • AS renames output columns; single quotes are for values, not identifiers
  • SELECT can contain expressions, not just column names
Check yourself