I have one table containing pages/ad and another table with x pictures for each ad.
The pictures table also have a “sortorder” column.
I’m trying to write some SQL, where i get the title from an ad and only one picture where sortorder is the lowest.
So far i’m doing this. But that just gave me a picture, but not the picture i want.
SELECT ads.id, ads.title, min(ads_gallery_files.filename) as picture, clients.name
FROM ads LEFT JOIN ads_gallery_files ON ads_gallery_files.ads_id=ads.id
GROUP BY ads.id
I also have a client table, where i can see who created the ad.
I’m using a left join to collect that name
LEFT JOIN clients ON clients.id=ads.client_id
Maybe i have to do a SELECT in a SELECT, don’t know.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…