I need to join two tables:
countries table
country|lang1|lang2|lang3|lang4
Canada |1 |2 |NULL |NULL
US |1 |NULL |NULL |NULL
and
languages table
id|language
1 |English
2 |French
I want to return the values for both rows in my countries table, with the language names.
How do I do that?
I tried:
SELECT * FROM en_countries LEFT JOIN all_languages
ON (all_languages.id = en_countries.lang1 AND all_languages.id = en_countries.lang2)
but that doesn’t give me the language names. How do I do this?
If someone could give me this in Active Record format, that would be a bonus. I’m doing this for CodeIgniter.
I think the issue here is with
(all_languages.id = en_countries.lang1 AND all_languages.id = en_countries.lang2)
rather try
The ‘and’ implies that one language should be the first and second language of a country, replacing it with ‘or’ may do the trick