title: how to pass value from main query inside a sub sub sub query
body: <p>i want to pass a variable from main query into the sub query. it is a problem since this query uses 3 subs.</p>
  
  <p>i've tried join but since i am new, its a bit confusing. the code is something like this</p>
  
  <pre><code>select fav.cust_id
  from 
  (
      select cust_id
      from
      (
          select cust_id
          from
          (
              select c.cust_id
              from customer c
          )
      )
  )fav
  where fav.cust_id = 12;
  </code></pre>
  
  <p>as we can see, im trying to pass the value '12' into the deepest sub query (c.cust_id) so that it return the intended values in the main query. if i try to pass the value in the first sub query, it will return wrong data as it tries to fetch all the data from the second sub query onward before using the condition. so what im trying to do is to pass the condition inside the deepest sub query so that it will filter the result from there to return the intended values.</p>
  
  <p>update:
  here is the close-to-real query that i made.</p>
  
  <pre><code>select fav.cust_lname, fav.cust_time
  from
  (
      select max(cust_lname), max(cust_time)
      --there is another code here for some calculations
      from
      (
           select lname cust_lname, time cust_time
           --there is another code here for some calculations
           from 
           (
                select c.cust_id
                --there is another code here for some calculations to return the cust_lname and cust_time
                from
                customer c
                where cust_g = 'MALE'
                AND cust_id = --in the original code, this is a parameter. i want this to read the value from the main query
           )
      )       
  )fav,
  customer_table ct
  
  where ct.header_id = --custom parameter that im trying to play with
  AND ct.cust_id = --i want to relate this with the cust_id inside the sub query
  
  </code></pre>