Select Most Recent Row Entered by Each User

I have this query.


SELECT
	*
FROM
	myTable
WHERE
	userId IN (5,9,10,15)
ORDER BY
	dateEntered DESC

I need to select only 1 most recently entered row for each userId. How?


SELECT
     m.*
  FROM
     (SELECT
           userId
           ,MAX(dateEntered) most_recent
        FROM
           myTable
       WHERE
           userId IN (5,9,10,15)
       GROUP
          BY
           userId) r
 INNER
  JOIN
     myTable m
    ON
     r.userId = m.userId
   AND
     r.most_recent = m.dateEntered
 ORDER
    BY
     m.dateEntered DESC

Hmm, now I have to study that thanks :slight_smile:

Do you mind writing one more query? Let’s omit the WHERE clause in my first query and add a limit.

SELECT
    *
FROM
    myTable
ORDER BY
    dateEntered DESC
LIMIT
    5

I need to select 5 most recently entered rows but each having a different userID. How?