Table Aliases

Learn how to use PostgreSQL table aliases to assign short temporary names to tables in queries — essential for joins, self-joins, and qualifying column names.

4 min read · Last updated: March 2026 · Back to overview

Quick Answer

A PostgreSQL table alias assigns a temporary short name to a table for the duration of a query. Aliases are declared with AS (or without it) in the FROM clause and are most useful for qualifying column names in joins and for self-joins where the same table is referenced twice.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

A table alias gives a table a temporary name within a query. Aliases make queries shorter and easier to read, are required for self-joins, and are essential for disambiguating column names when joining multiple tables that share column names.

Table alias syntax

table_name AS alias_name

The AS keyword is optional — both forms are valid:

FROM film AS f   -- with AS
FROM film f      -- without AS (equivalent)

Once an alias is defined, use it throughout the query to qualify column references: alias.column_name.

Basic table alias example

Assign the alias f to the film table and use it to qualify the column:

SELECT f.title
FROM film AS f
ORDER BY f.title
LIMIT 5;
title
------------------
 Academy Dinosaur
 Ace Goldfinger
 Adaptation Holes
 Affair Prejudice
 African Egg
(5 rows)

Using table aliases in joins

Table aliases are most valuable in JOIN queries to avoid ambiguous column names and to keep the SQL readable when joining tables with long names:

SELECT
  c.customer_id,
  c.first_name,
  p.amount,
  p.payment_date
FROM customer c
INNER JOIN payment p ON p.customer_id = c.customer_id
ORDER BY p.payment_date DESC;
customer_id | first_name  | amount |        payment_date
-------------+-------------+--------+----------------------------
         94 | Norma       |   4.99 | 2007-05-14 13:44:29.996577
        264 | Gwendolyn   |   2.99 | 2007-05-14 13:44:29.996577
        263 | Hilda       |   0.99 | 2007-05-14 13:44:29.996577
...

Using table aliases in self-joins

When a table is joined to itself (a self-join), table aliases are required — PostgreSQL needs distinct names to distinguish the two references to the same table:

SELECT
  f1.title,
  f2.title,
  f1.length
FROM film f1
INNER JOIN film f2
  ON f1.film_id <> f2.film_id
  AND f1.length = f2.length;
title            |            title            | length
-----------------+-----------------------------+--------
 Chamber Italian | Resurrection Silverado      |    117
 Chamber Italian | Magic Mallrats              |    117
 Chamber Italian | Graffiti Love               |    117
...

Without aliases f1 and f2, referencing film.title twice would be ambiguous and cause an error.

Practical tips for table aliases

  • Keep aliases short but meaningful: single-letter aliases like c for customer and p for payment are common. In complex queries with many tables, use two-letter abbreviations to keep them distinguishable.
  • Aliases are query-scoped: a table alias only lives for the duration of the query. It cannot be used outside the query or in a different statement.
  • Use aliases to qualify all columns in joins: prefix every column with its table alias in multi-table queries to eliminate ambiguity and make the query easier to audit.
  • Aliases are required for self-joins: you cannot reference the same table twice in a FROM clause without giving at least one reference an alias.

Reference: PostgreSQL documentation — Table Expressions.

Continue in Join Tables: PostgreSQL INNER JOIN.

Related in this section: PostgreSQL Joins · PostgreSQL INNER JOIN · PostgreSQL LEFT JOIN

Frequently Asked Questions

What is a table alias in PostgreSQL?

A table alias is a temporary name assigned to a table within a single query using the AS keyword (or without it). The alias replaces the table name for the duration of that query, making column qualification shorter and queries more readable.

Is the AS keyword required for table aliases in PostgreSQL?

No. The AS keyword is optional. "FROM film AS f" and "FROM film f" are equivalent. Both declare f as an alias for the film table. Most style guides include AS for clarity, but omitting it is equally valid SQL.

When are table aliases required?

Table aliases are required for self-joins — when a table is joined to itself, each reference must have a distinct alias so PostgreSQL can tell them apart. They are also practically necessary in any multi-table join to qualify ambiguous column names.

Can I use a table alias in a WHERE clause?

Yes. Once an alias is defined in the FROM clause, you can use it anywhere else in the same query — in SELECT, WHERE, JOIN, ORDER BY, GROUP BY, and HAVING clauses.

What is the difference between table aliases and column aliases?

A table alias renames a table reference within a query (FROM film AS f). A column alias renames a column in the output result set (SELECT title AS film_title). Table aliases are used to qualify column names and enable self-joins. Column aliases change the output column name and can be used in ORDER BY but not in WHERE or HAVING.