SQL AS renames a column or table to a more convenient alias (a correlation name) without changing the original names in the database. This makes writing queries easier when the original table or column names are long or complicated.
SQL AS: Main Tips
- SQL AS is used as a temporary name for the purpose of a particular SQL query.
- Aliases ensure better readability.
SQL AS for Columns
SELECT col_name AS al_name FROM tbl_name;
The example below describes both CustomerName and ContactName aliases.
When there are spaces between names of the columns, you must use square brackets or quotation marks:
SELECT ID as CustomerID, Name AS Customers FROM Customers;
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid certificates of completion
- Professional service
- Flexible timetables
- A variety of features to choose from
- Professional certificates of completion
- University-level courses
- Multiple Online degree programs
- Great user experience
- Offers quality content
- Very transparent with their pricing
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
SQL AS for Tables
SELECT col_name(s) FROM tbl_name AS al_name;
The example below picks out every order from customer with CustomerID=4. The aliases of the tables are given o and c for the orders and the customers table. This is done to make the SQL code shorter.
SELECT o.ID, c.Name FROM Customers AS c, Customer_orders AS o WHERE c.id = 2 AND c.ID = o.customer_id;
And a matching example with no alias:
SELECT Customer_orders.ID, Customers.Name FROM Customers, Customer_orders WHERE Customers.id = 2 AND Customers.ID = Customer_orders.customer_id;
In the table below you can see a piece of Customers table:
|1||Ben Choplinks||Ben Choplink||Obeesre Str. 51||Rome||11207||Italy|
|2||Donald Rich||Donald Richario||Avda. de la Confgfstitución 4122||Tallin||17021||Estonia|
|3||Lilly Smilkins||Lilly Smilkin||Matadsderos 2312||Eguero||14023||Mexico|
|4||Brandinina||Tom Hitchins||110 Hanegover Sq.||London||WB2 2DP||UK|
|5||Carizmos||Christiano Kerrys||Berguvsesvägen 9||Luleå||S-968 43||Sweden|
SQL AS: Summary
- Using alias does not change a column or table name in the original database.
- Aliases make complicated or long names easier read.
Latest Udacity Coupon Found:
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!