Have a query: SELECT image.image_id, offer_id FROM shop_item_param_image LEFT JOIN image ON shop_item_param_image.value = image.image_id
And 2 tables.
shop_item_param_image (offer_id, param_id, value) and image (image_id)
It is necessary to alter the query so that it gives the offer_id from the first table, if the second one does not have adjacent records