SELECT a.*, b.*, IF (b.eurosar = 1, ROUND(IF ((SELECT euroarfolyam FROM irodak WHERE iroda_id = a.iroda_id) > 0, (SELECT euroarfolyam FROM irodak WHERE iroda_id = a.iroda_id), 398.74 /*euroarfolyam*/) * b.ardecimal), b.ardecimal) AS euro_forint_iroda FROM idopont a, arak b WHERE a.ajanlat_id = '498547' /*sajatrow['ajanlat_id']*/ AND a.idopont_id <> '2015697349' /*sajatrow['idopont_id']*/ AND a.idopont_id = b.idopont_id AND a.idopont_status = 1 AND ( (a.idopont_szezonalis = 1 AND a.idopont_datum2 >= '2022-07-03' /*mavan*/) OR (a.idopont_szezonalis = 0 AND a.idopont_datum1 >= '2022-07-03' /*mavan*/) ) AND ( (a.idopont_arlejar > '0000-00-00' AND a.idopont_arlejar >= '2022-07-03' /*arlejar*/) OR (a.idopont_arlejar = '0000-00-00') ) ORDER BY a.idopont_datum1, b.ardecimal LIMIT 0,3 / MySQL server has gone away