Course contentsShow
← Data Science
Lesson 924 of 2,14524. SQL JoinsFree lesson

Using Table Aliases in Joins

Simplify queries and improve readability by assigning short aliases to table names in JOIN statements.

Using Table Aliases in Joins

You'll learn how to use short nicknames for table names to write cleaner, more readable JOIN queries.

When working with JOINs, repeatedly typing long table names can make your SQL queries cluttered and hard to read. Table aliases solve this problem by letting you assign short, temporary names to tables within a query.

The Core Idea

Think of table aliases like nicknames. Instead of saying "Jonathan" every time, you might say "Jon." Similarly, instead of writing customer_orders repeatedly, you can call it co throughout your query.

You assign an alias right after the table name in your FROM or JOIN clause. Here's the basic pattern:

SELECT c.first_name, o.order_date
FROM customers AS c
INNER JOIN orders AS o
  ON c.customer_id = o.customer_id;

In this example:

  • customers AS c creates the alias c for the customers table
  • orders AS o creates the alias o for the orders table
  • You then use c. and o. to specify which table each column comes from

Why Use Aliases?

Readability: c.customer_id is shorter and clearer than customers.customer_id, especially in complex queries.

Less typing: You save keystrokes, reducing errors and speeding up query writing.

Required for self-joins: When joining a table to itself (covered later), aliases become essential.

The AS Keyword is Optional

While you can write FROM customers AS c, most developers skip AS and simply write FROM customers c. Both work identically.

Key Takeaway: Table aliases are short, temporary names for tables that make JOIN queries easier to write and read, especially when dealing with multiple tables or long table names.