title: MySQL cannot access field from query within subquery
body: <p>I am struggling to resolve this problem. I have looked through many similar problems posted on here, but I can't find a workaround that works for me.</p>
  <p>I have three tables, <code>ctRequests</code> holds reservation requests made by each user, <code>ctBookings</code> holds details of confirmed reservations, <code>ctBookingsUsers</code> links a variable number of users with each confirmed booking.</p>
  <p>I need the query to return all <em>future</em> requests and cross-reference that with that user's last confirmed reservation <em>up to but not beyond</em> the date of the request. The problem I'm having is this statement returns the error &quot;unknown column: 'ctRequests.reqDate' in 'where clause' &quot;</p>
  <pre><code>SELECT reqID, reqDate, location, startTime, userID, userName, lastBooking
  FROM ctRequests
     LEFT JOIN
        (SELECT userID, MAX(resDate) AS lastBooking 
         FROM ctBookings 
            LEFT JOIN ctBookingsUsers 
            USING(bookingID)
         WHERE resDate &lt;= ctRequests.reqDate
         GROUP BY userID) prevBookings
     USING(userID)
     LEFT JOIN UserNames
     USING(userID)
  WHERE reqDate &gt;= NOW() 
  ORDER BY reqDate, location, startTime
  </code></pre>
  <p>Please can someone suggest how I can resolve this.</p>
  <p><strong>EDIT -</strong></p>
  <p>As requested, sqlFiddle can be found <a href="http://sqlfiddle.com/#!9/13b30b" rel="nofollow noreferrer">here</a></p>