在选择列表中只能指定一个表达式

时间:2011-05-21 09:31:34

标签: sql select join

我需要让这个SQL查询正常工作:

SELECT     TOP 15 id, thumb, width, height
FROM         (SELECT     vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height
                       FROM          vPictures INNER JOIN
                                              vPictureCrops ON vPictures.id = vPictureCrops.picid
                       WHERE      (vPictureCrops.width = '602') AND (vPictureCrops.height = '131')
                       GROUP BY vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height) AS derivedtbl_1
WHERE     (id NOT IN
                          (SELECT     TOP 0 vPictures_1.id, vPictures_1.datetime, vPictures_1.url, vPictures_1.author, vPictures_1.companyID, vPictures_1.source, 
                                                   vPictures_1.people, vPictures_1.text, vPictures_1.thumb, vPictures_1.logo, vPictureCrops_1.id AS Expr1, vPictureCrops_1.picid, 
                                                   vPictureCrops_1.url AS Expr2, vPictureCrops_1.width, vPictureCrops_1.height
                            FROM          vPictures AS vPictures_1 INNER JOIN
                                                   vPictureCrops AS vPictureCrops_1 ON vPictures_1.id = vPictureCrops_1.picid))
ORDER BY id DESC

你能帮助我吗?

错误讯息: “当未使用EXISTS引入子查询时,只能在选择列表中指定一个表达式”“

2 个答案:

答案 0 :(得分:1)

Where(ID不是IN(

Select必须只有一个字段,IN无法理解您要尝试解析的列。

例如来自here

USE AdventureWorks2008R2;
GO
SELECT p.FirstName, p.LastName
FROM Person.Person AS p
    JOIN Sales.SalesPerson AS sp
    ON p.BusinessEntityID = sp.BusinessEntityID
WHERE p.BusinessEntityID IN
   (SELECT BusinessEntityID
   FROM Sales.SalesPerson
   WHERE SalesQuota > 250000);
GO

无论如何不确定你想要用查询实现什么,你能解释一下where in子句的用法,

答案 1 :(得分:1)

我可以看到(id NOT IN (SELECT TOP 0 vPictures_1.id, ...

的两个问题
  1. 仅当在IN之后的select语句中指定列时。例如(id NOT IN (SELECT vPictures_1.id FROM ...

  2. 即使您只使用一个字段vPictures_1.id,由于top 0,条件也始终为假。