SQL Alias
With SQL, an alias name can be given to a table or to a column.
SQL 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.
SQL Alias Syntax for Tables
SELECT column_name(s)
FROM table_name
AS alias_name
|
SQL Alias Syntax for Columns
SELECT column_name AS alias_name
FROM table_name
|
Alias Example
Assume we have a table
called "Persons" and another table called "Product_Orders". We will give the
table aliases of "p" an "po" respectively.
Now we want to list all the orders that "Ola Hansen" is responsible for.
We use
the following SELECT
statement:
SELECT po.OrderID, p.LastName, p.FirstName
FROM Persons AS p,
Product_Orders AS po
WHERE p.LastName='Hansen'
WHERE p.FirstName='Ola'
|
The same SELECT
statement without aliases:
SELECT Product_Orders.OrderID, Persons.LastName, Persons.FirstName
FROM Persons,
Product_Orders
WHERE Persons.LastName='Hansen'
WHERE Persons.FirstName='Ola'
|
As you'll see from the two SELECT statements above; aliases can make queries easier to
both write and to read.
The Altova MissionKit is a suite of intelligent XML tools, including:
XMLSpy® – industry-leading XML editor
- Support for all XML-based technologies
- Graphical editing views, powerful debuggers, code generation, & more
MapForce® – graphical data mapping tool
- Drag-and-drop data conversion with code generation
- Support for XML, DBs, EDI, Excel® 2007, text, Web services
StyleVision® – visual stylesheet designer
- Drag-and-drop stylesheet design for XML & databases
- Output to HTML, PDF, RTF, Word 2007, & more
And more…
Try before you buy with a free fully functional 30-day trial
Download today
|
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.
The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).
|
|