SELECT I.*, IF(P.product_name_image=I.image_name,0,1) as sort FROM `cekqz_jshopping_products_images` as I left join `cekqz_jshopping_products` as P on P.product_id=I.product_id
WHERE I.product_id = '1000' ORDERBY sort, I.ordering