SQL Table Aliases

A short nickname for a table — barely useful with one table, essential once queries involve more than one.

What & Why

A table alias gives a table a short, temporary nickname for the rest of the query. On a single-table query it just saves typing; once JOINs enter the picture (a later lesson), it becomes essential for telling identically-named columns from different tables apart.

See How It Works

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT e.name, e.spend
FROM marketing.campaigns e;
RESULT — the alias changes query syntax, not output data
namespend
Spring Launch55000.00
Retention Webinar45000.00
Finance Retargeting50000.00
Enterprise Search60000.00

The e alias is valid only inside this query; the real table remains marketing.campaigns.

Now You Try

Practice this concept

SaaS leadership wants active account names, industries, and MRR using a short table alias.

Available schema
saas

Prefix tables with saas.table_name.

nameindustrymrr
saas.accounts
ColumnType
idinteger
nametext
plantext
mrrnumeric
created_attimestamp with time zone
churned_attimestamp with time zone
countrytext
employee_countinteger
industrytext
customer_segment_v2text
query.sql
Beginner business practice

Sign up free to try it on a real business scenario