0
I want to do a group by between two tables by doing an Inner Join. The employee table and the table employed at the post. I want it to return to the most recent entry into a post of a given employee. But I’m only getting this by having to delete two query columns, which is the contract post and the entry date in the post:
select
max(entrada_posto),
e.id ,
--ep.fk_posto_contrato,
e.admissao,
e.demissao,
--ep.entrada_posto,
ep.saida_posto
from TB_EMPREGADO e
inner join TB_EMPREGADO_NO_POSTO ep
on e.id = ep.fk_empregado
group by
e.id ,
--ep.fk_posto_contrato,
e.admissao,
e.demissao,
--ep.entrada_posto,
ep.saida_posto
Whose result is:
"MAX(ENTRADA_POSTO)","ID","ADMISSAO","DEMISSAO","SAIDA_POSTO"
"10/09/2018","1","10/09/2018","",""
"01/10/2020","43","09/13/2019","",""
The complete result with all columns, gives 2 entries for id 43, and I only need the last:
"MAX(ENTRADA_POSTO)","ID","FK_POSTO_CONTRATO","ADMISSAO","DEMISSAO","ENTRADA_POSTO","SAIDA_POSTO"
"01/10/2020","43","42","09/13/2019","","01/10/2020",""
"10/09/2018","1","21","10/09/2018","","10/09/2018",""
"10/09/2019","43","41","09/13/2019","","10/09/2019",""
Is there any way to preserve these columns and only bring the date of entry into the most recent post, to given employee id?
If there is a more effective solution, please let me know.
– Jose Gustavo Lima