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 det.mdet_estado = 'A' and det.mdet_msec_id = sec.mdet_id order by det.mde' at line 1