开发者

Multiple Alias names for a table

开发者 https://www.devze.com 2023-01-07 05:28 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消