Ever heard of JOIN
ing tables?
SELECT photo.id
FROM product_photo
INNER JOIN product_photo AS photo ON photo.product_id = product_photo.product_id
AND photo.order >= product_photo.order
WHERE product_photo.id = '33';
The FROM
and WHERE
parts will select your product id = 33
and then you join product_photo
with different alias (yes, you can join the same table multiple times in one query) based on product_id
and order
.
2
solved How minimize this mysql query [closed]