MySQL Forums
Forum List  »  Newbie

Re: Select first record of each ID mysql5.6
Posted by: Peter Brawley
Date: December 16, 2020 02:25PM

Rather than t1.sort=1, you want the minimum t.sort, which can be got with MIN() and requires Group By eg ...

SELECT t1.id, t1.foreign_id, t1.small_path, MIN(t1.sort) as 'sort', t2.title
FROM stivagallery_plugin_gallery t1  
JOIN stivagallery_galleries      t2 ON t1.foreign_id = t2.id
GROUP BY t1.id, t1.foreign_id, t1.small_path, t2.title
ORDER BY t1.foreign_id;

BTW do NOT use comma joins, they went out with quill pens, use JOIN ON... syntax as above.

Options: ReplyQuote


Subject
Written By
Posted
Re: Select first record of each ID mysql5.6
December 16, 2020 02:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.