SQL左外连接
在结果表中包含第一个表中满足的所有纪录,如果是在连接条件上匹配纪录,则第二个表返回相应的值,否则第二个表返回空值。
如:
select
hx.
name
,hx.age,hxhome.home
from
hx
left
join
hxhome
on
hx.id=hxhome.hxid
SQL右外连接
在结果表中包含第二个表中满足的所有纪录,如果是在连接条件上匹配纪录,则第一个表返回相应的值,否则第一个表返回空值。
如:
select
hx.
name
,hx.age,hxhome.home
from
hx
right
outer
join
hxhome
on
hx.id=hxhome.hxid
迫切左外连接
以下两种检索方式是等价的,它们都能同时迫切左外连接类B和类C:
//HQL迫切左外连接检索方式
from
A a
left
join
fetch
a.b b
left
join
fetch
a.c c
where
b
is
not
null
and
c
is
not
null
//QBC迫切左外连接检索方式
List result=session.createCriteria(A.class)
.setFetchMode(
"this.b"
,FetchMode.EAGER)
.setFetchMode(
"this.c"
,FetchMode.EAGER)
.
add
(Expression.isNotNull(
"this.b"
))
.
add
(Expression.isNotNull(
"this.c"
))
.list();