I have table:
Id, Name, Account, Date, ItemsToSend
- I want to group rows by NameandAccount
- From each group I want to get elements with latest Date
- And display element's Name,AccountandItemsToSend
I managed something like this:
select
    Name,
    Account,
    max(Date),
    max(CountItemsSend)
from History
where
    Date = (
        select max(Date)
        from History as p
        where
            p.Account = History.Account
            and p.Name = History.Name
    )
group by
    Name,
    Account
I am afraid of max(Date), max(CountItemsSend). I dont think it is ok. After where there is only 1 result for each group, so what is the point of max use there?
 
     
     
     
    