Invalid query: 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 implantes.estado=1 GROUP BY implantes.id,implantes_caract_vista.id_implante ' at line 31
SELECT implantes.id , implantes.nombre_s as nombre, group_concat( DISTINCT IF(implantes_caract_vista.tipo = 2, null, implantes_caract_vista.cont_s ) ORDER BY implantes_caract_vista.orden,implantes_caract_vista.id ASC SEPARATOR '&&' ) as caracts, group_concat( DISTINCT IF(implantes_caract_vista.tipo = 1, null, implantes_caract_vista.cont_s ) ORDER BY implantes_caract_vista.orden,implantes_caract_vista.id ASC SEPARATOR '&&' ) as apps, group_concat( DISTINCT fuente ORDER BY implantes_media.orden SEPARATOR '|' ) as media, IF(id_traba=NULL,0,CONCAT(trabas.id,'|',trabas.nombre_s,'|',trabas.cont_s,'|',trabas.id_instrumento)) as traba_data FROM implantes LEFT JOIN ( SELECT `implantes_aplicaciones`.`id` AS `id`,`implantes_aplicaciones`.`id_implante` AS `id_implante`,`implantes_aplicaciones`.`cont_e` AS `cont_e`,`implantes_aplicaciones`.`cont_s` AS `cont_s`,2 AS `tipo`,`implantes_aplicaciones`.`estado` AS `estado`,`implantes_aplicaciones`.`orden` AS `orden` from `implantes_aplicaciones` union select `implantes_caracteristicas`.`id` AS `id`,`implantes_caracteristicas`.`id_implante` AS `id_implante`,`implantes_caracteristicas`.`cont_e` AS `cont_e`,`implantes_caracteristicas`.`cont_s` AS `cont_s`,1 AS `tipo`,`implantes_caracteristicas`.`orden` AS `orden`,`implantes_caracteristicas`.`estado` AS `estado` from `implantes_caracteristicas` where (`implantes_caracteristicas`.`estado` = 1) order by `id_implante`,`tipo`,`orden`,`id` ) as implantes_caract_vista ON implantes.id=implantes_caract_vista.id_implante LEFT JOIN trabas ON implantes.id_traba=trabas.id LEFT JOIN implantes_media ON implantes.id=implantes_media.id_implante WHERE implantes.id_rubro= AND implantes.estado=1 GROUP BY implantes.id,implantes_caract_vista.id_implante ORDER BY implantes.orden