Good day!

There is such a table

id date date_over time user_id client_id 1 2017-11-22 2017-11-24 16:07:00 1 1 2 2017-11-22 2017-11-23 16:10:00 1 2 3 2017-11-24 2017-11-25 12:10:00 1 1 

Help to create a query to remove duplicates by client_id, and the most difficult thing for me here is to remove the old entries, that is, to make such a table

 id date date_over time user_id client_id 2 2017-11-22 2017-11-23 16:10:00 1 2 3 2017-11-24 2017-11-25 12:10:00 1 1 

that is, get the most recent date_over for each client

  • 2
    Well, group by client_id will certainly help you, only with the other columns decide which values ​​you want to get for them, minimum / maximum or something else smarter - Mike
  • @Mike Maximum I want a group by shows my first entries - Anton Kartushin

1 answer 1

All figured out thanks @Mike for the hint

 SELECT client_id, MAX(date_over) FROM crm.calls WHERE user_id = 1 GROUP BY client_id;