一个表的两个字段引用同一个外键,应该怎么查询
这么四张表.我想查询解决方案表中的记录 ,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 查询以上字段..为什么查询结果不显示任何记录,请大神们指出错误..希望给予一份标准的正确答案..谢谢了
------解决方案--------------------看你的代码,以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 解决建议 ,