1
I have a table with 300 thousand records and within it there are several different fields, I would like to take the line that contains the largest OUTGOING DATE calculated for each CPF_1
what I have:
ID NUMERO DATAEMISSAOAPURADA COD NOMEMUNICIPIORESIDENCIA UFRESIDENCIA CPF_1 CPF_2 FONTE NOME DATA DATA
----------- ------------------------- ----------------------- ----------------------- -------------------------------------------------- ------------ ------------- ------------- ------------------- ---------------------------------------------------------------------------- --------------------------- ---------------------------
12345 0000000000000009116092003 2007-11-19 00:00:00 4200051 Abdon Batista SC 123 321 TB1 To*********** 2012-10-28 00:00:00 NULL
78999 0000000000080697220782003 2007-11-09 00:00:00 4200051 Abdon Batista SC 123 321 TB1 To*********** 2012-10-28 00:00:00 NULL
12347 C000000000000000000821022 2006-04-12 00:00:00 2302404 Boa Viagem CE 356 978 TB1 JO********************** 2011-09-27 00:00:00 NULL
12399 C489895345345350000881240 2007-06-11 00:00:00 2306405 Itapipoca CE 876 093 TB1 HA************************* 2009-11-16 00:00:00 NULL
Expected result:
ID NUMERO DATAEMISSAOAPURADA COD NOMEMUNICIPIORESIDENCIA UFRESIDENCIA CPF_1 CPF_2 FONTE NOME DATA DATA
----------- ------------------------- ----------------------- ----------------------- -------------------------------------------------- ------------ ------------- ------------- ------------------- ---------------------------------------------------------------------------- --------------------------- ---------------------------
12345 0000000000000009116092003 2007-11-19 00:00:00 4200051 Abdon Batista SC 123 321 TB1 To*********** 2012-10-28 00:00:00 NULL
12347 C000000000000000000821022 2006-04-12 00:00:00 2302404 Boa Viagem CE 356 978 TB1 JO********************** 2011-09-27 00:00:00 NULL
12399 C489895345345350000881240 2007-06-11 00:00:00 2306405 Itapipoca CE 876 093 TB1 HA************************* 2009-11-16 00:00:00 NULL
https://forum.imasters.com.br/topic/512214-selecionando-item-max/? do=findComment&comment=2030107 see if it helps , subselect with MAX
– Motta
What version of SQL Server?
– José Diz