我有一张这样的桌子:
Email_tbl
plcid Ecode
----------- -----------
23 001646
24 001646
25 E004
25 2274
25 2208
25 1868我有另一张桌子Employee
Ecode Ename
E004 jaseem
2274 jasir
2208 deepu
1868 rupa
001646 shafeer我想得到Ename of plcid=25,所以我在这里使用这个查询:
SELECT em.Ename
FROM dbo.Email_tbl e
JOIN dbo.EmployeeMaster_tbl em ON em.Ecode IN (SELECT Ecode
FROM Email_tbl
WHERE plcid = 25)但我的结果出了问题。我的问题出什么问题了?
发布于 2013-09-10 12:27:42
SELECT em.Ename
FROM dbo.Email_tbl e
JOIN dbo.EmployeeMaster_tbl em ON em.Ecode = e.ECode
WHERE e.plcid = 25 发布于 2013-09-10 12:30:48
你为什么要加入这些桌子?为什么有三个答案“修复”一个不必要的连接?
SELECT em.Ename
FROM dbo.EmployeeMaster_tbl em
WHERE em.Ecode IN (SELECT Ecode
FROM Email_tbl
WHERE plcid = 25)发布于 2013-09-10 12:28:04
SELECT emp.Ename
FROM Email_tbl e INNER JOIN Employee emp ON (e.Ecode = emp.Ecode)
WHERE e.plcid = 25这将导致多行,因为Employee中的多行具有PLCID = 25的Ecode
https://stackoverflow.com/questions/18718884
复制相似问题