You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'n '' group by of.offer_id LIMIT 0, 1' at line 3 SQL=select * from jos_hotelreservation_offers of inner join jos_hotelreservation_offers_vouchers hov on of.offer_id = hov.offerId where REPLACE(hov.voucher,'-',' ') = '' n '' group by of.offer_id LIMIT 0, 1