This is not a 1:1
relationship. A country can have more the one company.
This is either a 1:N
relationship (for some reason implemented using two relational tables), or the M:N
relationship which describes multinational companies.
If this is a 1:N
relationship, you could just put the country_code
field into the companies
table, in which case one join would be enough:
SELECT *
FROM companies co
LEFT JOIN
countries cn
ON cn.country_code = co.country_code
Your design is viable for both 1:N
and M:N
relationships, in which case two joins are required:
SELECT co.*, cn.*
FROM companies co
LEFT JOIN
company_countries cc
ON cc.company_id = co.company_id
LEFT JOIN
countries cn
ON cn.country_code = cc.country_code
If this is a 1:N
relationship, you should make company_id
a PRIMARY KEY
in the company_country
table.
If this is a M:N
relationship, you should make a composite PRIMARY KEY
on company_country (company_id, country_code)
You may want to read this article in my blog about the difference between entity-relationship model and its relational implementation: