0

我有一个这样的查询:

SELECT  em.Ename 
FROM    dbo.Email_tbl e 
JOIN dbo.EmployeeMaster_tbl em ON em.Ecode = e.ECode
WHERE e.plcid='25'

这给了我这样的输出:

Ename
-------------------
Ahmed
Ahmed Elkhouli
akbar
Alaudddin

我有另一个这样的查询:

SELECT e.Ename 
from dbo.EmployeeMaster_tbl e 
WHERE e.gid not IN(SELECT did 
                   FROM dbo.Designation_tbl d 
                   WHERE d.Dname ='Driver'  )

我得到这样的输出:

Ename
--------------------------------------------------
Shaijomon John
Masum
Tausef Ahmad
Abdu Rahiman
Mohammad Shopan
Benzy P A
Mohammad Ali
Kauser Mohammad
Rasheed Pulakkuttathil
Lakshuman Perappan
Ahmed
Ahmed Elkhouli
akbar
Alaudddin 

我需要为第一个查询中不存在的行输出 ename。

所以我尝试了这样的查询:

SELECT e.Ename 
from dbo.EmployeeMaster_tbl e 
WHERE e.gid not IN(SELECT did 
                   FROM dbo.Designation_tbl d 
                   WHERE d.Dname ='Driver') 
and not in (SELECT  em.Ename 
            FROM  dbo.Email_tbl e 
            JOIN dbo.EmployeeMaster_tbl em ON em.Ecode = e.ECode 
            WHERE e.plcid='25')
order by e.Ename  

但我在关键字附近收到不正确的语法错误in

4

2 回答 2

0
SELECT e.Ename from dbo.EmployeeMaster_tbl e 
WHERE e.gid not IN 
(SELECT did 
FROM dbo.Designation_tbl d
 WHERE d.Dname ='Driver') 
 and e.name not in (SELECT  em.Ename 
 FROM  dbo.Email_tbl e 
JOIN dbo.EmployeeMaster_tbl em 
ON em.Ecode = e.ECode 
WHERE e.plcid='25')
order by e.Ename
于 2013-09-10T13:01:02.863 回答
0

试试这个,你e.Ename在哪里失踪

SELECT e.Ename from dbo.EmployeeMaster_tbl e 
 WHERE e.gid not IN(SELECT did FROM dbo.Designation_tbl d WHERE d.Dname ='Driver') 
 and e.Ename not in (SELECT  em.Ename FROM  dbo.Email_tbl e 
 JOIN dbo.EmployeeMaster_tbl em ON em.Ecode = e.ECode WHERE e.plcid='25')
 order by e.Ename
于 2013-09-10T13:01:27.757 回答