我有一个很长的查询语句,执行时会抛出异常。 查询语句:
SELECT HostID,HostName,RackID,HostTypeID,DomainName,RackNumberOfHeightUnits,RackStartHeightUnits
FROM tHosts, tDomains
WHERE tHosts.DomainID=tDomains.DomainID AND (RackID IN ( SELECT tRacks.Name,tRacks.RackID,tRacks.SiteID,tRacks.Description,NumberOfHeightUnits
FROM tDomains, tSites, tRacks
WHERE tDomains.AccountID= tSites.AccountID
AND tSites.SiteID = tRacks.SiteID
AND tSites.SiteID = 2
AND tDomains.AccountID=1 )
AND SiteID IN (SELECT SiteID FROM tSites WHERE SiteID IN (SELECT SiteID FROM tSites WHERE AccountID=1)))AND AccountID=1
这里实现了查询功能:
SELECT tRacks.Name,tRacks.RackID,tRacks.SiteID,tRacks.Description,NumberOfHeightUnits
FROM tDomains, tSites, tRacks
WHERE tDomains.AccountID= tSites.AccountID
AND tSites.SiteID = tRacks.SiteID
AND tSites.SiteID = 2
AND tDomains.AccountID=1
**错误提示: ** 当子查询未引入 EXISTS 时,只能在选择列表中指定一个表达式。
提前致谢。
AND (RackID IN ( SELECT tRacks.Name,tRacks.RackID,tRacks.SiteID,tRacks.Description,NumberOfHeightUnits
更改为AND (RackID IN ( SELECT tRacks.RackID
- artmjoin
语法。@artm 是正确的,但看起来您还需要从tRacks
中获取数据,因此您应该将其与外部查询进行join
。此外,这不是一个长查询,实际上相当短。 - HoneyBadger