0

我正在尝试将预先加入的表与另一个表并排加入,但它似乎不起作用。

这是代码:

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 相互匹配,因此我想交叉引用它们。

我做错了吗?

4

1 回答 1

2

停止执行隐式交叉连接。同样正如 ypercube 指出的那样,需要清理其他一些小东西,特别是删除重复的连接。

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
  INNER JOIN dyn_conformer c ON d.confid1 = c.id 
  INNER JOIN dyn_domainregion r ON r.domainid::varchar(8) = d.ddid
  INNER JOIN cath_domains a 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
于 2013-03-24T09:58:52.510 回答