select fields.content, min(fields.creation_date) as created
left join rates
group by fields.content
order by and
select f.* from fields f left join rates r on f.rate_id = r.rate_id where r.user_id = 4 order by f.creation_date asc limit 1;
Note that if there are ties (two records with the same
creation_date), then this will choose one arbitrarily.
Also, I suspect that you want:
select f.* from rates r left join fields f on f.rate_id = r.rate_id where r.user_id = 4 order by f.creation_date asc limit 1;
In your version, the
left join is not necessary -- it is turned to an inner join by the
where clause. Further, I would expect
f.rate_id to always match
r.rate_id, especially if you have a properly declared foreign key relationship. This will return a row even if there are no records in
fields (which appears to be your intention).