How to create an alias for a table in a PL/SQL SELECT query

September 23, 2007

You can create an alias for a table like this:

SELECT * FROM tablename newtablename WHERE conditions

For example

SELECT * FROM employee e1 WHERE e1.name = ‘Gandalf’

My college text-book ‘Fundamentals of Database Systems’ by Elmasri et al. says:

“It is generally advisable to create tuple variables (aliases) for all the tables referenced in an SQL query to avoid potential errors and ambiguities”

However I have found it necessary to use aliases only in rare situations; like when writing co-related sub-queries which involve the same table multiple times.

If you want to rename a table instead of referring to it by another name you will have to use ALTER TABLE.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s