午,跨表查询,写了很长的hql语句,就是出错!后来上网查查,方知hql语句的from不支持子查询,where支持!
如: select a from A a,(select b from B b,C c where b.id=c.id) d
where a.id=d.id;
改为→select a from A a where a.id in (select b.id from B b,C c
where b.id=c.id);
如: select a from A a,(select b from B b,C c where b.id=c.id) d
where a.id=d.id;
改为→select a from A a where a.id in (select b.id from B b,C c
where b.id=c.id);
本文介绍了在使用HQL进行数据库操作时,如何正确地利用子查询。特别指出HQL的from子句不支持子查询,但where子句可以实现这一功能,并通过一个具体的例子展示了正确的写法。
936

被折叠的 条评论
为什么被折叠?



