一个表的两个字段引用同一个外键,应该怎么查询
这么四张表.我想查询解决方案表中的记录 ,select SS_ID,S_SName as 软件名称,Emp_Name as 解决人员,SS_date as 解决时间,SS_Process as 解决建议,SS_Dsuggestion as 上级意见,(select Emp_Name from Lxl_EmpInfo,Lxl_Operator where O_ID=SS_Assessor) as 审核人,SS_Notes as 备注,SS_Operator as 操作员 from Lxl_Operator,Lxl_EmpInfo,Lxl_SoftwareInfo,Lxl_SoftwareSolution where O_ID=SS_Operator and O_ID=SS_Assessor and EMP_ID=SS_SSID and S_ID=SS_SID and SS_BZ = 0 查询以上字段..为什么查询结果不显示任何记录,请大神们指出错误..希望给予一份标准的正确答案..谢谢了 select SQL
[解决办法]
看你的代码,以Lxl_SoftwareSolution这个表为主表,通过关联查询才可以查出数据,你那样写代码都没有关联,那就是代表内联。所以没有符合条件的记录,应该用left join 关联查询
select SS_ID,S_SName as 软件名称,Emp_Name as 解决人员,
SS_date as 解决时间,SS_Process as 解决建议,f.Emp_name as 审核人,
SS_Dsuggestion as 上级意见,SS_Notes as 备注,SS_Operator as 操作员
from Lxl_SoftwareSolution a
left join Lxl_SoftwareInfo b on a.SS_ID=b.S_ID
left join Lxl_EmpInfo c on a.SS_SSID=c.Empl_ID
left join Lxl_Operator d on a.SS_Assessor=d.O_ID
left join Lxl_Operator e on a.SS_Operator=e.O_ID
left join (select O_ID,Emp_Name from Lxl_EmpInfo,Lxl_Operator where O_ID=SS_Assessor)f
on d.O_ID=f.O_ID
还有的,你的字段命名得不是那么规范,不易理解
[解决办法]
SELECT SS_ID ,
S_SName AS 软件名称 ,
Emp_Name AS 解决人员 ,
SS_date AS 解决时间 ,
SS_Process AS 解决建议 ,
SS_Dsuggestion AS 上级意见 ,
b.EmpName AS 审核人 ,
SS_Notes AS 备注 ,
SS_Operator AS 操作员
FROM Lxl_Operator a,
Lxl_EmpInfo b,
Lxl_SoftwareInfo c,
Lxl_SoftwareSolution d
WHERE a.O_ID = d.SS_Operator--外键
AND a.O_ID = d.SS_Assessor--外键
AND b.EMP_ID = d.SS_SSID--外键
AND c.S_ID = d.SS_SID--外键
AND d.SS_BZ = 0--看不到这个字段
--4个都是外键,没道理没有数据呀.除非你字段里的值存储的不对
--是不是最那个字段SS_BZ的原因