我正在Hibernate
与Mysql
合作我有三张桌子
我在这里
Employeedetails is referenced from Personaldetails
和Masterrecord is referenced from Employeedetails
但请注意 Masterrecord is not directly link from Personaldetails
我附上了
下面的结构格式
我的问题是:
我需要从个人详细信息
访问主记录记录以下查询无效
select a.fname,a.employeedetails.empId,a.employeedetails.masterrecord.deptCode from pojo.Personaldetails as a
我在Eclipse HQL编辑器中尝试了这个,它的工作原理如下:
我还有其他任何建议......
答案 0 :(得分:2)
试试这个
SELECT m.* From Masterrecord AS m
LEFT JOIN Employeedetails AS e ON e.DeotCode = m.DeotCode
LEFT JOIN Personaldetails AS p ON p.Refld = e.Refld
GROUP BY p.Refld
这只获取Masterrecord表值。如果需要相同的条件
SELECT m.* From Masterrecord AS m
LEFT JOIN Employeedetails AS e ON e.DeotCode = m.DeotCode
LEFT JOIN Personaldetails AS p ON p.Refld = e.Refld WHERE p.Refld = 101
GROUP BY p.Refld