In SQL, an alias is a name that you give a table. This can make it easier to work with table names — especially when they are long.
You could name the alias anything, but usually you'd make it short.
You may be thinking "a table already has a name, why give it another one?". Well, there are some good reasons for creating an alias. The main reasons are:
- Queries can sometimes get very long. Aliases can make your query easier to read.
- You may find yourself referencing the same table name over and over again — this will occur if you're working with multiple tables and you need to refer to columns from those tables. It can be annoying to have to write the whole name all the time - especially if it's a long one.
- You may need to work with multiple instances of the same table, for example, a self join. If you're not familiar with joins, they are covered later in this tutorial.
As mentioned, an alias could be anything. For example, if you have a table called
Individual you could give it an alias of
i. Another table called
IndividualProductPurchase could have an alias of, say,
SELECT * FROM table_name AS alias_name;
Example SQL Statement
SELECT o.JobTitle FROM Individual AS i, Occupation AS o WHERE i.FirstName = 'Homer' ORDER BY o.JobTitle;