I have two tables users and login_track. Each user may or may not have login records in login_track table. I want to retrieve recent 2 login dates for each user.
Table structures as below:
users:
user_id name
1 John
2 Mike
3 Anderson
.....
login_track:
track_id user_id login_date
100 1 2017-06-20
101 1 2017-06-21
102 2 2017-06-21
103 1 2017-06-23
104 2 2017-06-23
105 1 2017-06-27
So desired result should be.
user_id name login_date
1 John 2017-06-27, 2017-06-23
2 Mike 2017-06-23, 2017-06-21
3 Anderson NULL
Note : User id 3 (Anderson) has no records in login_track table, even though it should list in the final result with NULL value as login_date column.