0

我把 4 张桌子连在一起。

以后怎么参考?我可以或是否需要命名此表?

这是一个简单的内部连接:

select *
from table1 as 1
inner join table2 as 2 on x=y
inner join table3 as 3 on a=y
inner join table4 as 3 on z=a

现在当我稍后在代码中引用它时,我该怎么做?

我试图将所有内容(从 table1 到 z=a)放在括号中,并在其后面加上“as tablename”——它没有用。

有什么提示吗?

4

1 回答 1

1

Once you provide a name to the table alias, you would refer to the alias in your joins as well as in your SELECT list:

select t1.x,
  t2.y,
  t3.y,
  t4.a
from table1 as t1
inner join table2 as t2 
  on t1.x = t2.y 
inner join table3 as t3 
  on t1.a = t3.y
inner join table4 as t4 
  on t1.z = t4.a

You will see that when I provided the table alias' above I provided a name that began with a letter and not a number.

于 2013-03-04T12:09:39.153 回答