When and how to use table aliases

The syntax for an inner join that uses table aliases

      SELECT select_list
      FROM table_1 [AS] n1 
      [INNER] JOIN table_2 [AS] n2 ON n1.column_name operator n2.column_name 
      [[INNER] JOIN table_3 [AS] n3 ON n2.column_name operator n3.column_name]...
      

An inner join with aliases for all tables

      SELECT firstName, lastName, orderDate
      FROM customers c 
      INNER JOIN orders o ON c.customerID = o.customerID 
      ORDER BY orderDate;
      
table aliases image

An inner join with aliases for four tables

      SELECT firstName, lastName, o.orderID, productName, itemPrice, quantity
      FROM customers c 
      INNER JOIN orders o ON c.customerID = o.customerID 
      INNER JOIN orderItems oi ON o.orderID = oi.orderID 
      INNER JOIN products p ON oi.productID = p.productID 
      ORDER BY o.orderID;
      
4 table aliases image

Description

Back