5

我有一个选择查询,我想在其中对一个视图和另一个表进行连接。该视图工作正常,表格也可以单独工作。但是当我尝试做类似的事情时:

select VIEW.col1, VIEW.col2
from VIEW, TABLE
where VIEW.col1 = TABLE.col1

我明白了The multi-part identifier "VIEW.col1" could not be bound.

语法是错误的,还是视图中不允许这样做?

4

5 回答 5

10

这应该工作

select v.col1, t.col2
from VIEW v, TABLE t
where v.col1 = t.col1
于 2012-09-13T12:50:43.183 回答
1
SELECT VIEW.col1, VIEW.col2
from VIEW AS VIEW INNER JOIN TABLE AS TABLE
ON VIEW.col1 = TABLE.col1
于 2012-09-13T12:47:59.340 回答
1
SELECT MYVIEWNAME.col1, MYVIEWNAME.col2
FROM VIEWNAME AS MYVIEWNAME INNER JOIN TABLENAME AS MYTABLENAME
ON MYVIEWNAME.col1 = MYTABLENAME.col1
于 2012-09-13T12:51:18.960 回答
0

我建议您使用左连接或内连接,并为表和视图设置别名。

select v.col1 , v.col2

 from view v
 inner join table t on t.col1 = v.col1
于 2012-09-13T12:53:44.063 回答
0

你必须有view这样的:

create table MyView
as
select column1 as col1, column2 as col2
from tab

or

CREATE VIEW MyView (col1,col2)
as
select column1, column2
from tab

然后你可以加入它:

select MyView.col1, MyView.col2
from MyView, TABLE
where MyView.col1 = MyView.col1

or

select v.col1, v.col2
from MyView v, TABLE t
where t.col1 = t.col1

or

select v.col1, v.col2
from MyView v
join TABLE t on t.col1 = t.col1

也许某些示例不适用于所有 RDBMS。

于 2012-09-13T13:03:52.340 回答