I'm trying to create a list in PHP of the oldest entries for each user in the database.
SELECT *,
MIN(`entries`.`entry_date`)
AS entry_date
FROM (`entries`)
JOIN `user_profiles`
ON `user_profiles`.`user_id` = `entries`.`user_id`
WHERE `status` = 1
GROUP BY `entries`.`user_id`
I'm using the query to retrieve from the entries
table the oldest dated entry using MIN()
and joining with table user_profiles
for other data. The query should select the oldest entry for each user. It seems to work but it retrieves the wrong entry_date
field on some entries when I echo them. Please help, I can't spot what I'm doing wrong..