I have the following MySQL query, which works absolutely fine:
SELECT a.id, a.event_name, c.name, a.reg_limit-e.places_occupied AS places_available, a.start_date FROM nbs_events_detail AS a, nbs_events_venue_rel AS b, nbs_events_venue AS c, (SELECT e.id, COUNT(d.event_id) AS places_occupied FROM nbs_events_detail AS e LEFT JOIN nbs_events_attendee AS d ON e.id=d.event_id GROUP BY e.id) AS e WHERE a.id=b.event_id AND b.venue_id=c.id AND a.id=e.id AND a.event_status='A' AND a.start_date>=NOW() ORDER BY a.start_date
However, I am trying to add another WHERE
to filter out the results shown in the column created for the subtraction: a.reg_limit-e.places_occupied AS places_available
What I have done so far has been to add a WHERE
following form: WHERE places_available>0
However, if I try to use this instruction, the request will fail and the results will not be shown. The error is reported: #1054 - Unknown column 'places_available' in 'where clause'
In a.reg_limit
I have numbers, in e.places_occupied
I have numbers generated by COUNT
in a subquery. What am I missing?
source share