Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table alias in Sub queries

Status
Not open for further replies.

VE

Technical User
Oct 25, 2000
220
US

Other than readability and personal preference, are their any rules to aliasing tables in sub queries?

For instance, if you alias a table in the outer query AB, is there any scenario where giving a table in a sub query the alias AB would cause problems?

Or if a table used in the outer table is also used in a sub query should you give it a different alias in the sub query?

If it maters where can I find a list of rules? I don't seem to be using the right words when I search.

If it doesn't mater, what to you think it the most readable way to alias tables in sub queries?

Thank you
VE
 
search for sql server coding standards -- you will find many - take the good things out of them and ignore the rest - one example with good things is

In my opinion unique alias throughout as you never know if you are going to need to change a sub-query to a correlated query

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Use alias always if you join tables it make code clear
 
As gk53 indicated the alias help keep things clear. So it may not cause a SQL error to have the same alias within a subquery and query but it can get confussing. I do not have an example of where a problem might occur but ...

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top