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 'AND r.rng_id = fstc.rng_id AND fstc.fstc_status = 3 GROUP BY r.rng_id ORDER BY ' at line 1