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 structure is as below: Users:
user_id name
1 John
2 Mike
3 Anderson
4 William
.....
Login_track table:
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
4 William NULL
Note : User id 3 (Anderson) and 4 (William) has no records in login_track table, even though those two should also list in the final result with NULL value to login_date column.
Thanks.