Leakbali
w3 Tutorial, Web Tutorial
Switch to English Bahasa Indonesia 
Register   Login

MySQL - Alias


You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names. An alias name could be anything, but usually it is short.

MySQL Alias Syntax for Tables

SELECT column_name(s)
FROM table_name
AS alias_name

MySQL Alias Syntax for Columns

SELECT column_name AS alias_name
FROM table_name

MySQL Alias Example

Assume we have a table called "Persons" and another table called "Orders". We will give the table aliases of "p" and "o" respectively. Now we want to list all the orders that "Haru Sanjaya" is responsible for. We use the following SELECT statement:
SELECT o.OrderID, p.LastName, p.FirstName
FROM Persons AS p, Orders AS o
WHERE p.FirstName='Haru' AND p.LastName='Sanjaya'
The same SELECT statement without aliases:
SELECT Orders.OrderID, Persons.LastName, Persons.FirstName
FROM Persons, Orders
WHERE Persons.FirstName='Haru' AND Persons.LastName='Sanjaya'
As you'll see from the two SELECT statements above; aliases can make queries easier to both write and to read.

References

About Us

Home
About Us
Contact Us
Sitemap

Tools

Google PageRank
Alexa Rank
Keywords Density

Accounts

Register Account
Login
Valid XHTML 1.0 TransitionalValid CSS!
Web Directory


2006 - 2012 © Leakbali.com - Free Web Tutorial, Free Web Articles, Web Sharing, Source Codes, Web References