This example is based on Scott's sample schema whose tables simulate what you have.
SQL> SELECT ename, hiredate
2 FROM emp
3 ORDER BY hiredate DESC;
ENAME HIREDATE
---------- ----------
ADAMS 12.01.1983 --> Adams has the MAX hiredate; you want his data
SCOTT 09.12.1982
MILLER 23.01.1982
FORD 03.12.1981
JAMES 03.12.1981
KING 17.11.1981
MARTIN 28.09.1981
TURNER 08.09.1981
CLARK 09.06.1981
BLAKE 01.05.1981
JONES 02.04.1981
WARD 22.02.1981
ALLEN 20.02.1981
SMITH 17.12.1980
14 rows selected.
Using a CTE which includes the RANK
analytic function that "sorts" rows by hiredate
in descending order (so that people - who have the MAX hiredate
- rank as "highest")), in final query you just fetch those whose rank = 1:
SQL> WITH
2 temp
3 AS
4 (SELECT e.ename,
5 d.dname,
6 e.hiredate,
7 RANK () OVER (ORDER BY e.hiredate DESC) rn
8 FROM emp e JOIN dept d ON e.deptno = d.deptno)
9 SELECT ename, dname, ROUND ((SYSDATE - hiredate) / 365) age
10 FROM temp
11 WHERE rn = 1;
ENAME DNAME AGE
---------- -------------- ----------
ADAMS RESEARCH 39
SQL>
Applied to your query:
WITH
temp
AS
(SELECT a.applicantfirstname,
a.applicantlastname,
o.officename,
a.birthdate,
RANK () OVER (ORDER BY a.birthdate DESC) rn
FROM applicant a JOIN office o ON o.officeid = a.officeid)
SELECT applicantfirstname,
applicantlastname,
officename,
ROUND ((SYSDATE - birthdate) / 365) AS age
FROM temp
WHERE rn = 1;