MorkaLork Development

Interesting stuff I've picked up over the years...

Mysql 12: ALIAS

2009-04-16 21:19:52 | 150 views | sql mysql table alias header keyword

ALIAS:

Now, normally we might create a table with a "functional" header to a column, like store_name or store_sales which describes the data that is held in that column. If you however want to output the data to a visual table, you might want to change the name of that column header to something less describing and more catchy, such as changing store_sales to just Sales or store_name to just Store. Using the ALIAS keyword, this can be achieved.


This will be our table 'stores'

store_namestore_salesstore_updates
Hanks Hardware25002009-01-01
Santos SuperStore7502008-12-01
Bobs Boutique12502009-01-01
Patty´s Pantstore10502008-12-15
Hanks Hardware17502008-01-01



Syntax:

SELECT table_alias.column column
FROM column


Example:


SELECT store_name Store, SUM(store_sales) Sales
FROM stores
GROUP BY store_name


StoreSales
Bobs Boutique1250
Hanks Hardware4750
Patty´s Pantstore1050
Santos SuperStore750



Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.