SELECT Statement

Control exactly which columns appear in your output

Beginner 12 minSELECTcolumnsalias

SELECT: Choosing Your Columns

Every SQL query starts with SELECT — the verb that tells the database which columns to return. You can pick specific fields, create aliases, or compute entirely new columns on the fly. Here's what you can do:

Pick specific columnsSELECT name, price FROM products returns only those two fields. This keeps results focused, improves performance, and avoids accidentally exposing sensitive columns like passwords.
Avoid SELECT * in production — The wildcard * grabs every column. Convenient for quick exploration, but wasteful and risky in real applications where you want tight control over what data gets returned.
Rename with AS (aliasing)SELECT price AS original_price changes how the column appears in the result without touching the actual table. Useful for creating clear, report-friendly labels in your output.
Compute new columns — SQL evaluates expressions on the fly: SELECT price * 1.1 AS price_with_tax produces a column that doesn't exist in the table. You can use math, string functions, or any valid expression.
Knowledge Canvas

How SELECT Works

The foundation of every SQL query

  • SELECT picks which columns appear in your output
  • Column order in SELECT = column order in result
  • SELECT * returns all columns — exploration only
  • AS creates aliases that rename output columns

Warnings & Gotchas

Mistakes that catch everyone

  • SELECT * hides schema changes — broken code waits silently
  • Aliases don't change the actual table — only the output label
  • Forgetting commas between column names → syntax error
  • Column order matters for UNION but not for readability

Power Patterns

Techniques that level up your queries

  • SELECT DISTINCT removes duplicate rows
  • Computed columns: price * quantity AS total
  • String concatenation: first || ' ' || last AS full_name
  • Conditional output: CASE WHEN ... END AS label
DISTINCTexpressionsCASE

Critical Rules

Memorize these

  • Always name specific columns in production code
  • AS aliases are for display — they don't modify data
  • SELECT runs after FROM, WHERE, GROUP BY, HAVING
  • Expressions in SELECT can reference any column in scope

Naming & Aliasing

Best practices for readable queries

  • Use snake_case for aliases: total_revenue, not TotalRevenue
  • Keep aliases short but descriptive
  • Alias computed columns always — unnamed columns cause confusion
  • Wrap aliases in double quotes if they contain spaces or keywords

Interview Angle

What interviewers look for

  • Can you explain SELECT execution order?
  • "When would you use SELECT * vs named columns?"
  • Show awareness of computed columns and CASE
  • Demonstrate alias discipline in complex queries
Syntax
Syntax Template
1-- Specific columns
2SELECT
3 column1,
4 column2
5FROM table_name;
6
7-- With alias (renames the output column only)
8SELECT
9 column AS alias_name
10FROM table_name;
11
12-- All columns + computed expression
13SELECT
14 *,
15 price * 0.9 AS discounted
16FROM products;
SELECT *Selects all columns — convenient for exploration, avoid in production
SELECT col1, col2Selects specific columns by name
AS aliasRenames a column in the output only
ExpressionsYou can use math, string functions, etc. in SELECT
Sample Data
products
10 rows
idnamecategorypricestock
P101Wireless MouseElectronics24.99150
P102Office DeskFurniture18925
P103LED Desk LampFurniture45.580
P104USB-C CableElectronics12.99500
P105Bluetooth SpeakerElectronics7960
P106Office ChairFurniture9515
P107Coffee MakerAppliances89.9940
P108Notebook SetStationery8.5200
P109Wireless HeadphonesElectronics15930
P110Standing DeskFurniture4258

Worked Example

Show product names and their prices with a 10% discount applied.

SQL
1SELECT
2 name,
3 price AS original_price,
4 ROUND(price * 0.9, 2) AS discounted_price
5FROM products;
We select the product name, show the original price with an alias, and calculate a discounted price using a math expression. ROUND(..., 2) limits the result to 2 decimal places. The discounted_price column does not exist in the table — it is computed on the fly.
Output
5 rows
nameoriginal_pricediscounted_price
Wireless Mouse24.9922.49
Office Desk189170.1
LED Desk Lamp45.540.95
USB-C Cable12.9911.69
Bluetooth Speaker7971.1
Common Mistakes

Using SELECT * everywhere

SQL
1SELECT
2 *
3FROM products;

Grabbing all columns is tempting but wasteful. It slows queries on large tables, makes results harder to read, and can accidentally expose sensitive data.

Name the columns you actually need. Only use * for quick exploration.

AS is optional, but clarity is not

SQL lets you write SELECT price discounted (without AS). While valid, it is confusing to read and easy to misparse.

Always use AS explicitly: SELECT price AS discounted.

Key Concepts

1SELECT * is for exploration only — name columns in production
2Aliases (AS) affect output labels, never the actual table
3You can SELECT expressions that don't exist as columns
4Column order in SELECT determines column order in the result

Pro Tip

SELECT is the verb of SQL. You cannot retrieve any data without it. Mastering column selection, aliases, and computed expressions gives you complete control over query output.

When to Use

API responses, CSV exports, dashboard feeds, report generation — they all start with choosing the right columns.

Challenge

Solve the problem below

Write a query that shows the name, category, and stock for all products. Rename "stock" to "units_available".

Your Query