title: Join self-join table with another table
body: <p>I have two tables: products and meta.</p>
  
  <p>Products table:</p>
  
  <pre><code>+----+----------+
  | id | name     |
  +----+----------+
  |  1 | TV       |
  |  2 | Computer |
  |  3 | Freezer  |
  +----+----------+
  </code></pre>
  
  <p>Meta table:</p>
  
  <pre><code>+----+------------+-----------+------------+
  | id | product_id | meta_key  | meta_value |
  +----+------------+-----------+------------+
  |  1 |          1 | currency  | USD        |
  |  2 |          1 | price     | 1100       |
  |  3 |          2 | currency  | PLN        |
  |  4 |          2 | price     | 9300       |
  |  5 |          3 | currency  | USD        |
  |  6 |          3 | price     | 1200       |
  +----+------------+-----------+------------+
  </code></pre>
  
  <p>now the following query works fine:</p>
  
  <pre><code>select price.product_id, products.name, price.meta_value as 'price', currency.meta_value as 'currency' 
  from meta as price
  join meta as currency on(price.product_id=currency.product_id and currency.meta_key='currency')
  join products on(products.id=price.product_id)
  where price.meta_key='price';
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>+------------+----------+-------+----------+
  | product_id | name     | price | currency |
  +------------+----------+-------+----------+
  |          1 | TV       | 1100  | USD      |
  |          2 | Computer | 9300  | PLN      |
  |          3 | Freezer  | 1200  | USD      |
  +------------+----------+-------+----------+
  </code></pre>
  
  <p>but the query:</p>
  
  <pre><code>select price.product_id, products.name, price.meta_value as 'price', currency.meta_value as 'currency' 
  from meta as price, meta as currency
  join products on(products.id=price.product_id)
  where
      price.product_id=currency.product_id
      and price.meta_key='price'
      and currency.meta_key='currency';
  </code></pre>
  
  <p>returns: "Unknown column 'price.product_id' in 'on clause'"</p>
  
  <p>Why does that happen ?</p>