the table design is
images_id, product_id, file_name, rank
1, 1, cat1.jpg, 11
2, 1, cat2.jpg, 12
3, 2, dog1.jpg, 8
4, 2, dog2.jpg, 9
5, 2, dog3.jpg, 10
Becasue image_id has nothing to do with this sql, I didn't bring that field in my sample.
Due to I don't have large number records before. What I did before is get the unqiue product ids first. And loop for each product id, assign as $this_product_id
select * from product_images where product_id=$this_product_id order by rank limit 0, 1
but if the number of products incorease, such as for 100 products, it will have to do 100 times sql.
So I am looking for an efficient sql solution here now.
Thanks!