SQL QUERY ISSUE(不在)

时间:2011-02-28 14:02:31

标签: sql sql-server-2005

select NAME  
from Temp_EMP 
where name not in  select NAME from  EMPLOYEE  and deptid ='11'

我在声明中收到错误。

3 个答案:

答案 0 :(得分:2)

您缺少子查询中的WHERE子句:

select NAME from Temp_EMP where name not in (select NAME from EMPLOYEE WHERE deptid ='11')

答案 1 :(得分:1)

Verrigo很接近,但我认为应该更像这样:

select [NAME]
from Temp_EMP
where name not in (
    select [Name]
    from EMPLOYEE
) and deptid = '11'

我假设deptidTemp_EMP上的一列,而deptid实际上是一些文字字段。

约什

答案 2 :(得分:0)

尝试

select [NAME] from Temp_EMP where [name] not in (select NAME from EMPLOYEE) and deptid ='11'

或者,我认为这有点优化:

Select [Name] from temp_emp t left join
employee on e on t.[name]=e.[name]
where e.[name] is null and t.deptid = '11'