S
S
Senture2019-12-05 20:30:35
SQL
Senture, 2019-12-05 20:30:35

How to select the latest entries of each ID?

Hello, I have this request:

SELECT
  *
FROM Table_1
ORDER BY Id, DateUse DESC

Here is the result:
5de93e8a30e4b401729120.png
And you need to get only what is marked with arrows in the screenshot, please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Samsonov, 2019-12-05
@Senture

SELECT *
FROM Table_1 t1
LEFT JOIN Table_1 t2 ON t2.id = t1.id AND t2.DateUse > t1.DateUse
WHERE t2.id IS NULL;

K
Konstantin Tsvetkov, 2019-12-05
@tsklab

SELECT Table_Senture.* FROM Table_Senture
  INNER JOIN ( SELECT ID, MAX(DateUse) AS MaxDate FROM Table_Senture GROUP BY ID ) AS MR
    ON Table_Senture.ID = MR.ID AND DateUse = MaxDate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question