w3reference home
SQL Tutorial


Bookmark and Share

SQL Aliases

You can give an alias to any column or any table in SQL by using the AS statement. This temporary name can be used in the output of a query to enhance the clarity and avoid ambiguity.
Syntax for column:
SELECT column_name1 AS alias1, column_name2 AS alias2,....
FROM table_name;
Syntax for table:
SELECT column_name1, column_name2,....
FROM table_name AS alias1;
Consider the table, Emp_Add given below:
ssn fname lname address city state
512687458 Joe Smith 83 First Street Howard Ohio
758420012 Mary Scott 842 Vine Ave. Losantiville Ohio
102254896 Sam Jones 33 Elm St. Paris New York
876512563 Sarah Ackerman 440 U.S. 110 Upton Michigan
Suppose, we want to display fname as FirstName and lname as LastName in the output. The query for the same will be:
SELECT fname AS FirstName, lname AS LastName
FROM Emp_Add;
The output will be:
FirstName LastName
Joe Smith
Mary Scott
Sam Jones
Sarah Ackerman
The name of our table is Emp_Add, which is quite big. We might want to shorten it for our convenience. Suppose, we want to use the name, emp instead of Emp_Add. The SQL query for the same would be:
SELECT emp.fname AS FirstName, emp.lname AS LastName
FROM Emp_Add AS emp;
In the above query, we have used the shortened name emp instead of it's original name. The output will be the same as the above.
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.