Hi,

I have a query that I would like the company_id from the outer Select for use in the subquery, but no matter what I try I get 'Unknow column 'c.company_id' in 'on clause'. I have read the MySQL documentation and I think that I am doing it the way they specify, but I might not have interpreted it correctly. Can you see why this doesn't work or how it can be done?

Code:
SELECT
  c.company_id as 'Company Id'
  , (SELECT
       p.phone_number
     FROM 
       phone_numbers as p
     WHERE
       p.company_id = c.company_id) as 'Phone Number'
  , a.address as 'Address'
FROM
  companies as c
INNER 
  JOIN companies2addresses as c2a
    ON c2a.company_id = c.company_id
INNER
  JOIN addresses as a
    ON a.address_id = c2a.address_id;
Thanks
Steve