在Sql Query中只能指定一个表达式

时间:2016-01-04 12:05:21

标签: sql sql-server sql-server-2012

在Sql Query

中只能指定一个表达式
select PageID
    from page
    where PageID in (select DocumentId
                     from PDFDocument
                     where DocumentId in (select * from RunDocument)
                    )

enter image description here

2 个答案:

答案 0 :(得分:3)

您有select *,其中只需要一列。您可以通过提及列来解决此问题:

select PageID
from page
where PageID in (select DocumentId
                 from PDFDocument
                 where DocumentId in (select DocumentId from RunDocument)
---------------------------------------------^
                );

答案 1 :(得分:2)

你可以这样试试。

SELECT pg.PageID
FROM   page pg
       INNER JOIN PDFDocument pd
               ON pd.DocumentId = pg.PageID
       INNER JOIN RunDocument rd
               ON rd.DocumentId = pd.DocumentId 

使用子查询

SELECT pg.PageID
FROM   page pg
WHERE  EXISTS (SELECT 1
               FROM   PDFDocument pd
                      INNER JOIN RunDocument rd
                              ON rd.DocumentId = pd.DocumentId
                                 AND pd.DocumentId = pg.PageID);