Multiple Alias names for a table
Can we have multiple alias names fo开发者_Go百科r a single table?
Yes. You need to do this for a self join, for example f you have a table storing a hierarchy:
create table Foo (
FooID int
,ParentFooID int
,[columns]
)
You can do a join to get the children of parents that satisfy a particular condition with a query like:
Select b.*
from Foo a
join Foo b
on a.FooID = b.ParentFooID
and [some condition filtering a]
No, not on the same table, but you can select the same table twice and give each a different alias.
SELECT alias1.*, alias2.*
FROM mytable alias1, mytable alias2
This will then allow you to use the same table for a different purpose within a single query.
精彩评论