Есть запрос:
SELECT `charges`.*,
DATE_FORMAT(`CHARGE_DATE`, '%b %e, %Y') AS `DATE`,
`groupclasses`.`CODE` AS `CLASS`,
IFNULL((SELECT SUM(`AMOUNT`) FROM `payments_to_charges`
WHERE `CHARGE_ID`=`charges`.`ID`),'0.00') AS `AMOUNT_PAID`,
CONCAT(IFNULL(FIRSTNAME,''),' ', IFNULL(LASTNAME,'')) AS CLIENT
FROM `charges`
LEFT JOIN `groupclasses` ON (`charges`.`CLASS_ID`=`groupclasses`.`ID`),
`members`
WHERE
`charges`.`MEMBER_ID`=`members`.`ID` AND
`charges`.`ID` > 0 AND `charges`.`MEMBER_ID`= '1031'
пробую его расширить:
SELECT `charges`.*,
DATE_FORMAT(`CHARGE_DATE`, '%b %e, %Y') AS `DATE`,
`groupclasses`.`CODE` AS `CLASS`,
IFNULL((SELECT SUM(`AMOUNT`) FROM `payments_to_charges`
WHERE `CHARGE_ID`=`charges`.`ID`),'0.00') AS `AMOUNT_PAID`,
CONCAT(IFNULL(FIRSTNAME,''),' ', IFNULL(LASTNAME,'')) AS CLIENT,
CONCAT(IFNULL(members2.FIRSTNAME,''),' ', IFNULL(members2.LASTNAME,'')) AS STUDENT
FROM `charges`
LEFT JOIN `groupclasses` ON (`charges`.`CLASS_ID`=`groupclasses`.`ID`),
left join `members` as `members2` on(`charges`.`STUDENT_ID` = members2.ID),
`members`
WHERE
`charges`.`MEMBER_ID`=`members`.`ID` AND
`charges`.`ID` > 0 AND `charges`.`MEMBER_ID`= '1031'
В итоге выдаёт ошибку. В чём может быть проблема?
members
asmembers2
on(charges
.STUDENT_ID
= members2.ID), ' at line 10