I have a table Mark with id and name fields and second table with mark_id and two extra columns I’m interested in. I want to get all records from Mark table + priority for that mark and created_at. There might be several created_at values but I do not care much about them, I need just need one (first, whatever).
I tried this query which gives me too much records, 5 instead of 3 I expect.
SELECT
marks.*,
markings.created_at,
markings.created_at AS updated_at,
markings.priority
FROM `marks`
JOIN markings
ON marks.id = markings.tag_id
WHERE (created_at > '2011-11-06 12:05:01')
AND (priority = 1)
ORDER BY created_at;
where
marks.col1, marks.col2, ... marks.colnwould bemarks.id, marks.namein your case if you don’t have more columns you don’t tell us about.