Error: MYSQL ERROR:

SELECT DISTINCT 
					var.variant_title,
					var.price_mentions,
					var.variant_title,
					var.price_mentions,
					var.ws_show_price_type,
					var.own_barcode,
					var.nr_customization_options,
					var.show_sales_leads_form_id,
					var.product_weight_kg,var.custom_barcode,
					var.mymarketplace_offer_count,
					fm.pret_vanzare,fm.createtime,
					fm.stoc-fm.reserved_stoc AS stoc,
					fm.discount_type,
					fm.discount_value,fm.valuta_id_vanzare,fm.pret_vanzare_cu_tva,
					val.rovidites as valuta_txt,var.cod_varianta,var.cod_produs,
					val.curr_suffix AS currency_suffix,
					fm.product_link,fm.last_update_stamp,
					fm.rec_id AS fisa_de_magazie_id,
					var.rec_id AS variant_id,
					var.stoc_furnizor_um1,
					var.charact_fixe_serialized,
					var.stoc_um1-var.reserved_stoc AS stoc_um1,
					var.is_new_until,
					var.charact_fixe_cache,
					var.charact_fixe_single_cache,
					var.ws_option_charact_labels_serialized,
					var.ws_option_characts_cache_serialized,
					var.flag_has_resigilat,
					var.flag_has_legat,
					var.product_template_id,
					tva.rec_id AS tva_id,tva.cota AS tva_cota,
					fm.pret_vanzare_discounted,
					fm.pret_vanzare_cu_tva_discounted,
					fm.discount_valid_through_date,
					um1.den AS um1_den,
					ROUND(fm.discount_percent_la_pret_recomandat,2) AS discount_percent_la_pret_recomandat,
					IF (discount_percent_la_pret_recomandat>0,2,IF (discount_valoric_la_pret_recomandat>0,1,0)) AS pret_recomm_discount_type
					,prvc.characts_values_icon_urls_cache
					,prt.additional_description AS prt_additional_description
					,var.average_rating
					,var.rating_count
					,prv_texts.variant_specifications_text
					,pic.rec_id AS pic_id, pic.file_name, 1 AS status_permits_order  , 0 AS producator_discount_percent
					 
				FROM product_variants_345 as var
				JOIN fisademagazie_345 AS fm
					ON fm.magazia=1 AND var.rec_id=fm.variant_rec_id AND NOT fm.deleted
				LEFT JOIN valuta_345 AS val ON val.rec_id=fm.valuta_id_vanzare
				LEFT JOIN UM_345 AS um1 ON um1.rec_id=fm.unitate_masura
				LEFT JOIN product_variant_caches_345 AS prvc ON prvc.prv_id=var.rec_id
				LEFT JOIN product_variants_texts_345 AS prv_texts ON prv_texts.prv_id=var.rec_id
				LEFT JOIN product_templates_345 AS prt ON prt.rec_id=var.product_template_id
				LEFT JOIN tva_percentages_345 AS tva
					ON tva.rec_id = fm.cota_tva_vanzare_id
                    
				 LEFT JOIN poze_produse_345 AS pic ON pic.correct_pr_variant_id = var.rec_id AND NOT pic.hidden 
							
				 
				WHERE  var.cod_varianta='7699' 
					AND var.is_published
					AND NOT var.deleted
					AND NOT var.is_archived
					 AND (var.stoc_um1>0 OR var.stoc_furnizor_um1>0)
				GROUP BY var.rec_id
				ORDER BY IF((var.stoc_um1-var.reserved_stoc)>0 && fm.pret_vanzare_cu_tva>0,0,1), fm.pret_vanzare_cu_tva, var.variant_title, var.charact_fixe_cache,var.cod_produs


Out of resources when opening file '/tmp/#sql_28db_2.MAI' (Errcode: 24 "Too many open files")