dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 25, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Selecting Data from Views with Aliases

Question:
If I have created a view from two tables that happen to have a similar column name (e.g., name) :
CREATE VIEW team AS SELECT p.name, p.age, t.name, t.city 
FROM PLAYER p, TEAM t where ...
How do I then select this information from the view? Do I have to use the same aliases?

Answer:
The aliases of "p" and "t" are only for the table names. To create a view that includes columns of the same name, you need to create an alias for the column, like this:

CREATE VIEW team AS SELECT p.name AS PName, p.age AS PAge, 
t.name AS TName, t.city AS TCity FROM PLAYER p, TEAM t
where ....
Then you access the columns by their aliases, like this:
SELECT PName, PAge, TName
FROM Team
If you try to create a view with columns of the same name, it will return an error.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date