Given the schema
The following query
SELECT a.user_id,
a.date_created,
avg(ai.level) level
FROM assessment a
JOIN assessment_item ai ON a.id = ai.assessment_id
GROUP BY a.user_id, a.date_created;
Returns these results
user_id, a.date_created, level
1, "2015-07-13 18:26:00", 4.0000
1, "2015-07-13 19:04:58", 6.0000
13, "2015-07-13 18:26:00", 2.0000
13, "2015-07-13 19:04:58", 3.0000
I would like to change the query such that only the earliest result is returned for each user. In other words, the following should be returned instead
user_id, a.date_created, level
1, "2015-07-13 18:26:00", 4.0000
13, "2015-07-13 18:26:00", 2.0000