informix SQL中的表别名范围

时间:2013-09-01 06:05:25

标签: sql informix

在以下示例SQL

select * from (
  select col
  from myTable mt
  inner join anotherMyTable amt on mt.id = amt.id
) as t
where 
  exists (select amt.colX from anotherMyTable amt where amt.id = 42)

'amt'别名在两个地方定义。声明第二个表别名与第一个名称相同是否正确,或者我应该使用其他名称(amt2)?

在这个例子中,我假设两个别名都位于不同的范围内,因此可以使用相同的名称。我使用Informix DBMS。

P.S。这是一个示例SQL,问题只是关于表别名范围。

1 个答案:

答案 0 :(得分:1)

在此范围内:

exists (select amt.colX from anotherMyTable amt where amt.id = 42)

没有定义amt别名,因此您可以使用此别名。

以下两个例子都是错误的:

select * from (
  select col
  from myTable amt
  inner join anotherMyTable amt on amt.id = amt.id
) as t
where 
  exists (select amt.colX from anotherMyTable amt where amt.id = 42)


select * from (
  select col
  from myTable mt
  inner join anotherMyTable amt on mt.id = amt.id
) as amt
where 
  exists (select amt.colX from anotherMyTable amt where amt.id = 42)
相关问题