MySQL Forums
Forum List  »  Newbie

Select first record of each ID mysql5.6
Posted by: Dave F
Date: December 16, 2020 12:47PM

Hi, complete newbie, be gentle with me.....
I have the following query in a php file which works fine to select the first row for each user id based on the sort field, but as soon as a user deletes the first entry the record is not found so what I would like to do is select by the lowest value in the sort field for each id, but I don't have a clue how to do it.
My webhost uses mysql 5.6, it's basically creating an index page picking an image path for each id to link to a proper page.
Any help greatly appreciated, I'm a mechanic not a programmer so simple is best....
Query below.
$sql = "
SELECT
t1.id,
t1.foreign_id,
t1.small_path,
t1.sort,
t2.title
FROM
stivagallery_plugin_gallery t1,
stivagallery_galleries t2
WHERE t1.foreign_id = t2.id
And t1.sort = '1'
ORDER BY t1.foreign_id ";

Options: ReplyQuote


Subject
Written By
Posted
Select first record of each ID mysql5.6
December 16, 2020 12:47PM


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.