I have the following tables:
EMPLOYEE
ID |NOMBRE | APELLIDO
1 |TEST | TEST
2 |TEST2 | TEST2
3 |TEST3 | TEST3
4 |TEST4 | TEST4
DIRECTION
ID | DIRECCION | EMP_ID | PAIS_ID |FECHA_INSERCION
1 | DIR1 | 1 | 1 |10/10/2019 08:00:00
2 | DIR2 | 1 | 1 |10/10/2019 08:15:00
3 | DIR3 | 1 | 5 |10/10/2019 08:20:00
I want to get the last registered address of the employee
for instance
TEST | TEST | DIR1 | 5 | 10/10/2019 08:20:00
I have tried the following query
Select Nombre,Apellido, Pais_ID, DIRECCION, MAX(FECHA_INSERCION)
FROM EMPLEADO EMP
INNER JOIN DIRECCION DIR ON EMP.ID = DIR.EMP_ID
GROUP BY Nombre, Apellido, Pais_ID, DIRECCION
However this gets me the following:
TEST | TEST | DIR1 | 1 | 10/10/2019 08:15:00
TEST | TEST | DIR1 | 5 | 10/10/2019 08:20:00
How could I fix the query to get what I need?