SELECT p.id, p.url, p.name, p.coords, p.annotation, i.filename as image FROM s_products p LEFT JOIN s_images i ON i.product_id=p.id AND i.position=(SELECT MIN(position) FROM s_images WHERE product_id=p.id LIMIT 1) WHERE p.coords IS NOT NULL GROUP BY p.id