我有一个选择查询,我想在其中对一个视图和另一个表进行连接。该视图工作正常,表格也可以单独工作。但是当我尝试做类似的事情时:
select VIEW.col1, VIEW.col2
from VIEW, TABLE
where VIEW.col1 = TABLE.col1
我明白了The multi-part identifier "VIEW.col1" could not be bound.
语法是错误的,还是视图中不允许这样做?
这应该工作
select v.col1, t.col2
from VIEW v, TABLE t
where v.col1 = t.col1
SELECT VIEW.col1, VIEW.col2
from VIEW AS VIEW INNER JOIN TABLE AS TABLE
ON VIEW.col1 = TABLE.col1
SELECT MYVIEWNAME.col1, MYVIEWNAME.col2
FROM VIEWNAME AS MYVIEWNAME INNER JOIN TABLENAME AS MYTABLENAME
ON MYVIEWNAME.col1 = MYTABLENAME.col1
我建议您使用左连接或内连接,并为表和视图设置别名。
select v.col1 , v.col2
from view v
inner join table t on t.col1 = v.col1
你必须有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。