SQL Alias

previous next


With SQL, aliases can be used for column names and table names.


Column Name Alias

The syntax is:

SELECT columnName AS columnAlias FROM tableName;

 


Table Name Alias

The syntax is:

SELECT columnName FROM tableName AS tableAlias;

 


Example: Using a Column Alias

This "Books" table:

Title

Author

Publisher

Year

الدورة الدموية

إبن النفيس

دار العلم

1650

Java 2

L. Johnston

Fast Press

2002

Linux and Unix

J. Sam

Fast Press

2004

Operating Systems

M. Stone

Coriolis

2005

Web Programming

K. Yariv

East Edition

2005

XML Language

M. Salim

Knowledge Press

2000

And this SQL:

SELECT Title AS Book_Title, Year AS Publication_Year FROM Books;

Returns this result:

Book_Title

Publication_Year

الدورة الدموية

1650

Java 2

2002

Linux and Unix

2004

Operating Systems

2005

Web Programming

2005

XML Language

2000

 


Example: Using a Table Alias

The same "Books" table given above and this SQL:

SELECT Title, Author FROM Books AS Documents;

Returns this result:

Table Documents:

Title

Author

الدورة الدموية

إبن النفيس

Java 2

L. Johnston

Linux and Unix

J. Sam

Operating Systems

M. Stone

Web Programming

K. Yariv

XML Language

M. Salim

 


Test your SQL Skills

To test your SQL skills click here.


previous next