【发布时间】:2012-01-07 00:28:36
【问题描述】:
我正在尝试将预先加入的表与另一个表并排加入,但它似乎不起作用。
代码如下:
SELECT
r.domainid,
r.dombegin AS DomainStart,
r.domend AS Domain_End,
d.ddid,
d.confid1 AS confid,
c.pdbcode,
c.chainid,
a.pdbcode AS "cath_pdbcode",
c.pdbcode
FROM dyn_dyndomrun d, cath_domains a
INNER JOIN dyn_conformer c ON d.confid1 = c.id
INNER JOIN dyn_domainregion r ON r.domainid::varchar(8) = d.ddid
INNER JOIN dyn_conformer AS c ON a.pdbcode::character(4) = c.pdbcode
UNION ALL
SELECT
NULL,
NULL,
NULL,
NULL,
NULL,
d.ddid,
d.confid2,
c.pdbcode,
c.chainid
FROM dyn_dyndomrun d
INNER JOIN dyn_conformer c ON d.confid2 = c.id
ORDER BY confid ASC
这一行有问题
FROM dyn_dyndomrun d, cath_domains a
INNER JOIN dyn_conformer c ON d.confid1 = c.id
INNER JOIN dyn_domainregion r ON r.domainid::varchar(8) = d.ddid
INNER JOIN dyn_conformer AS c ON a.pdbcode::character(4) = c.pdbcode
这是错误:
ERROR: invalid reference to FROM-clause entry for table "d"
LINE 11: INNER JOIN dyn_conformer c ON d.confid1 = c.id
^
HINT: There is an entry for table "d", but it cannot be referenced from this part of the query.
********** Error **********
ERROR: invalid reference to FROM-clause entry for table "d"
SQL state: 42P01
Hint: There is an entry for table "d", but it cannot be referenced from this part of the query.
Character: 236
最后,我想要一个包含"domainid, domainstart, domainend, ddid, confid, chainid, pdbcode from conformer and the chain id" 的表,除此之外,我还想要另一个表中的一组新列,例如"pdbcode from cath_domains, cathbegin, cathend"。
conformer 和 cath_domains 的 pdbcode 相互匹配,因此我想交叉引用它们。
我做错了吗?
【问题讨论】:
-
关心发布您遇到的错误?
-
ERROR: invalid reference to FROM-clause entry for table "d" LINE 11: INNER JOIN dyn_conformer c ON d.confid1 = c.id ^ HINT: There is an entry for table "d", but it cannot be referenced from this part of the query. ********** Error ********** ERROR: invalid reference to FROM-clause entry for table "d" SQL state: 42P01 Hint: There is an entry for table "d", but it cannot be referenced from this part of the query. Character: 236 -
尝试使用唯一别名。您的查询定义了表
d两次。 -
尝试更改您的 second from 子句。
FROM dyn_dyndomrun d2等 -
可能是因为您从两个基表中进行选择。使用两个表之一启动您的 FROM,并在另一个表中进行 INNER JOIN。
标签: sql postgresql join inner-join union-all