Hi people i have the table DORIG in my db. In this table i have all the row of the invoice.
The table have this structure
id_Dorig, Cd_Cf, datadoc, cd_ar and more other field that are not usefull.
What i whant is data of the last document for all the article.
The data that i want extract is
Cd_ar , datadoc , cd_cf
If i use select MAX(datadoc) , cd_ar from dorig group by cd_ar
I have the cd_ar and the data but i can't extract the cd_cf. If i insert it in the query, duplicate result.
Thank you
************************************************ the world is strange but people are crazy
you were close. to just get other data you just needed to modify it as
SELECT t.*
FROM dorig t
INNER JOIN (select MAX(datadoc) AS MaxDate, cd_ar
from dorig group by cd_ar
)t1
ON t1.cd_ar = t.cd_ar
AND t1.MaxDate = t.datadoc
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/