SELECT user_id, date_time, journal_id FROM logs WHERE user_id = 1
user_id | date_time | journal_id
1 | 2014-02-04 11:15:00 | 21
1 | 2014-02-04 11:25:00 | 22
1 | 2014-02-04 14:00:00 | 31
1 | 2014-02-05 10:15:00 | 33
1 | 2014-02-05 12:55:00 | 45
1 | 2014-02-05 15:15:00 | 48
1 | 2014-02-05 15:35:00 | 49
1 | 2014-02-06 05:00:00 | 62
1 | 2014-02-06 13:40:00 | 67
1 | 2014-02-06 15:00:00 | 72
I would like to select the first 3 rows for each date (*note that the 5th of feb. has 4 rows), and I was thinking if its do-able with count or limit, but without any luck. I have been looking for solutions, but havent had any luck. Mostly I would really like to know if it's do-able with MySQL, or if I just have to do some date checking in PHP instead, to remove the unwanted rows from the result.
The actual result I'm aiming for would be this:
user_id | date_time | journal_id
1 | 2014-02-04 11:15:00 | 21
1 | 2014-02-04 11:25:00 | 22
1 | 2014-02-04 14:00:00 | 31
1 | 2014-02-05 10:15:00 | 33
1 | 2014-02-05 12:55:00 | 45
1 | 2014-02-05 15:15:00 | 48
1 | 2014-02-06 05:00:00 | 62
1 | 2014-02-06 13:40:00 | 67
1 | 2014-02-06 15:00:00 | 72
Any ideas?