开发者

I want to replace the "left outer join" with an alternate basic query, how can I do it?

The query looks like this:

Select t1.开发者_高级运维*, t2.balance from t1 left outer join t2 on (t1.id1 = t2.id1 and t1.id2 = t2.id2)
where t1.name = 'name';

I was good until I was using native queries but now I need to use Hibernate's JPA implementation for all the queries. The involved table are not associated in any way.

That's why I want to use the alternate fundamental query equivalent to left outer join.

Thanks, Mahesh


My only suggestion would be to UNION the results of two queries, the inner join and then the rows from t1 without a match in t2, something like:

Select t1.*, t2.balance from t1, t2 where t1.name = 'name' and t1.id1 = t2.id1 and t1.id2 = t2.id2
UNION
Select t1.*, null where t1.name = 'name' and (t1.id1,t1.id2) not in (select id1, id2 from t2)
;

I'm not familiar with Hibernate and so don't know if this gives you the same issue. I suppose in the worst case if you really can only execute basic queries then having two independent queries and combining the results in code may have to suffice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜