Quick Search:
 
 The Oracle ALIAS Keyword      [Return To Index] Jump to:  

Term: ALIAS

Definition:
The ALIAS keyword allows a TABLE or COLUMN to be given a "shorthand" name in an SQL statement. This short name is referred to as an alias. Aliases are especially be helpful if the SQL statement is complex or the table or column names are long.

Column aliases exist to help organize output and using them generally makes the output of the query much more readable.

Table aliases created by putting the alias name directly after the table name in the FROM clause. The keyword AS is used to assign an alias to the column or a table.

Example Usage

Lets say we have a table called "user_list" and another table called "member_type". We want to get data from both tables for the name 'John Smith'. Without using aliases, this is what the SQL might look like:

SELECT
member_type.user_info,
user_list.last_name,
user_list.first_name
FROM user_list,
member_type
WHERE user_list.last_name='Smith' AND user_list.first_name='John';


Now we'll write the same SQL, but to make it easier we'll give the user_list table an alias of "U" and the member_type table an alias "M":

BASE>SELECT M.user_info, U.last_name, U.first_name
FROM user_list AS U,
member_type AS M
WHERE U.last_name='Smith' AND U.first_name='John';


As you can see, the SQL statement with aliases is more compact and simpler to write.
Related Code Snippets:
 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org