title: MySQL: using main query variable on sub-sub-query
body: <p>I'm trying to create query that will show me table of stock, name of the stock, id, date, url, price and list of prices from the last 2 weeks.
  <br><br>
  For the 14 days history I used sub-query with group_concat on the select.
  <br><br>
  <strong>But when I use group_concat it's return all results and ignore my limit, so I created another sub-query that will be the 14 prices and the group_concat will make it a list.</strong>
  <br><br>
  The table 'record_log' is records for all stocks:<br>
  parent_stock_id - the actual stock this line belongs<br>
  price - the price<br>
  search_date - date of the price<br>
  <br>
  The second table is 'stocks':<br>
  id - id of the stock<br>
  name, market_volume....</p>
  
  <p><strong>Here is the problem:</strong><br>
  In the sub-sub-query (last line of the SELECT), when i'm filtering parent_stock_id=stocks.id he don't recognize the stocks.id because it belongs to the main query.<br>
  <strong>How can I take the stock_id from top and pass it to the sub-sub-query? or maybe another idea?</strong></p>
  
  <pre><code>SELECT
      stocks.id AS stock_id,
      record_log.price AS price,
      record_log.search_date,
      (SELECT GROUP_CONCAT(price) FROM (SELECT price FROM record_log WHERE parent_stock_id=stocks.id ORDER BY id DESC LIMIT 14) AS nevemind) AS history
  FROM stocks
  INNER JOIN record_log ON stocks.id = record_log.parent_stock_id
  WHERE
      record_log.another_check !=0
  </code></pre>
  
  <p>Thank you!</p>
  
  <p><em>--- I'm are not really using it for stocks, it's just was the easiest way to explain :)</em></p>