I'm having a problem in the where clause of my INNER JOIN subquery. I'm receiving a unknown column error for M.idMembre
. I've tried using the table name instead of the alias but I get the same issue. I've also tried removing the WHERE clause from the subquery and adding this condition in the ON clause after the subquery. However, I'm having the same issue either way. I feel it's something obvious I'm missing here.
SELECT DISTINCT M.`idMembre` , `couponsTypes`.`maxCouponType`
FROM membres AS `M`
INNER JOIN (
SELECT idMembre, MAX( coupons.`idType` ) AS `maxCouponType`
FROM coupons
WHERE coupons.`idMembre` = M.`idMembre`
GROUP BY idMembre
) AS `couponsTypes`
ON M.`idMembre` = couponsTypes.`idMembre`
ORDER BY maxCouponType DESC
Let me know if you need more information.