0
user_id      date      
-------    ---------
1          1551867583
2          1551867580
3          1551867573
2          1551867543
2          1551867521

I have a similar table structure. What I want to do is to select records per user and select the latest one of each user's record.

Tried

GROUP BY profile_visits.user_id ORDER BY profile_visits.date DESC

This doesn't show all the latest records.

I searched and found this on StackOverflow

group by and order by in mysql query

However, that solution didn't work for me

Any idea how to solve this?

Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130
  • 1
    SO doesn't like "didn't work for me". SO likes "didn't work for me because...". See: [Why should I provide an MCVE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Mar 06 '19 at 10:35
  • I don't exactly know why it didn't work thats why I didn't write "because" ! – Utku Dalmaz Mar 06 '19 at 10:39

1 Answers1

0

You can use max date and group by

select max(date) max_date, user_id 
from  my_table 
group by user_id  
order by user_id, max_date
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107