i've found a workaround using a subquery, instead the second
table name
in the join, to order the photos ascending by their id. that
way the
GROUP BY always choose the first photo when grouping by shop
...
LEFT JOIN (SELECT id_shop,photo FROM photos_shop ORDER BY
id_photo) AS
photos
...
John Doe wrote:
> hi:
>
> i have this master page listing some shops with a
thumbnail and some data:
>
>
http://www.fashiontraveler.com/newsite/sdct_shoplst.php?m=12&brand=242&country=150&city=2406
>
>
> if you click in the "see more +" link a detail page is
loaded showing
> more photos and data
>
> the problem is the client wants the thumbnail in the
master page to be
> the first photo introduced (that with lower id_photo) as
listed in the
> detail page
>
> i'd say the GROUP BY clause should always return the
last photo
> corresponding to a shop but as you can see, the first 2
shops show the
> last and the other 3 show the first photo as thumbnail!?
>
> "SELECT
shops.id_shop,name,address,zip,phone,text,photos_shop.photo
> FROM shops
> LEFT JOIN photos_shop ON shops.id_shop =
photos_shop.id_shop
> GROUP BY shops.id_shop
> ORDER BY name";
>
> tia,
>
> jdoe