I currently have two tables, one for pages (objects) and one for images (media).
I want to get a list of all the pages in the system, and join a single image record onto each page record. It’s very close to working now, but it is returning all of the records, when I just want to get one back.
I’ve tried a few sub queries + Distinct, but not quite got it working yet.
Can anyone point me in the right direction. I’ve tried group by, but it doesn’t work after doing the sort and therefore brings back the wrong image.
SELECT title,
url,
media_file,
media_order
FROM ndxz_objects
LEFT JOIN ndxz_media ON ndxz_objects.id = ndxz_media.media_ref_id
WHERE `status` = 1
AND `section_id` = 2
GROUP BY title, url, media_file, media_order
ORDER BY ndxz_objects.ord, ndxz_media.media_order
I didn’t find that query worked, this is what I used in the end.
I found this from the within group aggrigates section here which seems like a good group of sql examples