Probably the simplest query, you need to select data from the table, only by the latest date for [Application code].

SELECT Comment. [Application code], Comment.com, Max (Comment.date_com) AS [Max-date_com] FROM Comment GROUP BY Comment. [Application code], Comment.com;

What am I doing wrong? Displays exactly the latest date. And yet, in one day there can be several records, how to display only one, the last one?

  • You need something like SELECT Comment. [Application code], Comment.com, Comment.date_com AS [Max-date_com] WHERE date_com = max (date_com) FROM Comment GROUP BY Comment. [Application code], Comment.com; but it is not exactly. - HasmikGaryaka
  • @ Eugene if you need to get the latest comment text for each application: first get the last date for each application - then join the application number and date of the table with you, while you have the last date for each comment to the application - Serge Nazarenko
  • How to get exactly the latest date? I choose a few dates, that's the problem. - Eugene
  • @HasmikGaryaka, at your request, swears that - It is impossible to use the aggregate function in the WHERE clause date_com = max (date_com) - Eugene

1 answer 1

request text:

SELECT Comment.[Код заявки], Comment.com, Comment.date_com FROM (SELECT [Код заявки] ,Max(date_com) AS lastdate FROM Comment GROUP BY [Код заявки] ) AS lastc INNER JOIN Comment ON Comment.[Код заявки] = lastc.[Код заявки] and Comment.date_com = lastc.lastdate 
  • Something I swear at the absence of the operator. And the sequence is the same? - Eugene
  • It seems Access requires the use of AS. Write instead of) lastc =>) AS lastc - Sergey Moiseenko
  • @SergeyMoiseenko thanks - added as - Serge Nazarenko
  • @ Eugene corrected the request - try now - Serge Nazarenko
  • Bravo, by date selects! Now would remove the duplicates by one date and super! - Eugene