【发布时间】:2016-02-16 13:50:09
【问题描述】:
我有一个员工表和描述表,如下所示。
员工表:
empId empName
================
1 foo
2 bar
说明表:
id description empId
======================
1 test A 1
2 test B 1
3 test C 1
4 test D 2
5 test E 2
6 test F 1
我可以加入并使用某事查询获取每个员工的最新描述,
select e.empId, e.empName, d.description
from employee e
inner join description d on d.id=(select max(id) from description where empId=e.empId)
这将返回所需的结果
empId empName description
===================================
1 foo test F
2 bar test E
但我想知道有没有其他方法可以在没有子查询的情况下获得相同的结果。
【问题讨论】:
-
根据手册中的章节,您可以在没有子查询的情况下执行此操作,但未关联的子查询解决方案几乎肯定会更快