title: Should a subquery on a join use tables from an outer query in the where clause?
body: <p>I need to add a subquery to a join, because one payment can have more than one allotment, so I only need to account for the first match (where rownum = 1). </p>
  
  <p>However, I'm not sure if adding pmt from the outer query to the subquery on the allotment join is best. </p>
  
  <p>Should I be doing this differently in the event of performance hits, etc.. ? </p>
  
  <pre><code>      SELECT
              pmt.payment_uid,
              alt.allotment_uid,
  
          FROM
              payment pmt
  
  /* HERE: is the reference to pmt.pay_key and pmt.client_id 
     incorrect in the below subquery? */
  
              INNER JOIN allotment alc ON alt.allotment_uid = (
                  SELECT
                      allotment_uid
                  FROM
                      allotment
                  WHERE
                          pay_key = pmt.pay_key
                      AND
                          pay_code = 'xyz'
                      AND
                          deleted = 'N'
                      AND
                          client_id = pmt.client_id
                      AND
                          ROWNUM = 1
              )
  
          WHERE
  
              AND
                  pmt.deleted = 'N'
              AND
                  pmt.date_paid &gt;= TO_DATE('2017-07-01')
              AND
                  pmt.date_paid &lt; TO_DATE('2017-10-01') + 1;
  </code></pre>