SELECT p.*, ph.*
FROM products AS p
INNER JOIN product_photos AS ph
ON p.product_id = ph.product_id
LEFT JOIN product_photos AS ph2
ON p.product_id = ph2.product_id
AND ph2.photo_order < ph.photo_order
WHERE ph2.photo_order IS NULL
ORDER BY p.product_title ASC
Bemærk, hvordan den forbindes til tabellen product_photos to gange. WHERE ph2.photo_order IS NULL
smider alt undtagen den laveste fotorækkefølge. Det vil dog ikke beskytte dig mod duplicate product_id / photo_orders combo, men du kan tilføje en GROUP BY
på p.id, hvis det er tilfældet.