关键字'in'附近的语法不正确

时间:2013-10-24 08:40:14

标签: sql-server

对于以下查询,我收到此错误:

  

Msg 156,Level 15,State 1,Line 3:关键字'in'

附近的语法不正确

查询:

SELECT shedule.shedulId, shedule.shedudate, shedule.hometeam, shedule.awayteam
FROM shedule
where in
(Select homeplay.shedulId from homeplay, shedule where shedule.shedulId != homeplay.shedulId);

5 个答案:

答案 0 :(得分:1)

将评论读到另一个回复,我认为你正在寻找这个:

SELECT h.shedulId, 
       s.shedudate, 
       s.hometeam, 
       s.awayteam
FROM   homeplay h 
LEFT OUTER JOIN  
       shedule s ON 
       h.shedulId = s.shedulId
WHERE  s.shedulId IS NULL

答案 1 :(得分:0)

你需要IN操作员面前的东西。

SELECT shedule.shedulId, shedule.shedudate, shedule.hometeam, shedule.awayteam
FROM shedule
where SOMETHING_IS_MISSING_HERE in (Select homeplay.shedulId
                                    from homeplay,shedule
                                    where shedule.shedulId!=homeplay.shedulId)

或者您是否尝试使用IN代替EXISTS?

答案 2 :(得分:0)

IN

的示例用法
SELECT p.FirstName, p.LastName, e.JobTitle
FROM Person.Person p
JOIN HumanResources.Employee AS e
    ON p.BusinessEntityID = e.BusinessEntityID
WHERE e.JobTitle IN ('Design Engineer', 'Tool Designer', 'Marketing Assistant');
GO

有关详细信息,请参阅here

答案 3 :(得分:0)

正确的陈述是:

SELECT shedule.shedulId, shedule.shedudate, shedule.hometeam, shedule.awayteam
FROM shedule
WHERE shedule.shedulId IN
(SELECT homeplay.shedulId FROM homeplay, shedule WHERE shedule.shedulId != homeplay.shedulId);

答案 4 :(得分:0)

请试试这个,它会给你想要的结果

select s.shedulId, s.shedudate, s.hometeam, s.awayteam
from shedule s left join homeplay h on s.shedulId=h.shedulId
where h.shedulId is null