- 作者:zhaozj
- 发表时间:2020-12-23 10:39
- 来源:未知
1 .from
1.1单表查询
from eg.cat as cat.其中,cat只是一个别名,为了用其他子语句的时候书写简单
1.2多表查询
from eg.Cat,eg.Dog from eg.Cat as cat,eg.Dog as dog 2 join相关 (inner) join left (outer) join right (outer) join full join HQL同样对SQL中的这些特性支持 下面插播一个小话题,关于上边的那些特性,我一直都没怎么用,今天既然说到这里,就想 把上边的几个特性的用法说一下,也算对自己的一个补充: 假设有两个表:部门、员工,下面列举一些数据: 员工(Employee): ID Name DepNo 001 Jplateau 01 002 Jony 01 003 Camel 02 部门(Department): ID Name 01 研发部 02 营销部 在Hibernate中我们操纵的都是对象,所以我们操纵的是部门类和员工类 1).(inner) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee join Department as department on employee.DepNo= department.ID (注意到条件语句我用on 没有用where) 那么执行结果是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 2).left (outer) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee left join Department as department on employee.DepNo= department.ID 那么执行结果又该是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 003 Camel null null {就是说此时我要已第一个表的记录多少为准,第二个表中没有相应纪录的时候填充null} 3). right (outer) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee right join Department as department on employee.DepNo= department.ID 那么执行结果又该是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 null null 02 营销部 {就是说此时我要已第二个表的记录多少为准,第一个表中没有相应纪录的时候填充null}