I have two tables. One table with the letters of different countries and a second table with a mapping of these letters to each other.
I need to make a query to get the mapped letters of the two languages. Can you tell me how this can be done optimally?
The letter table
id | letter | language |
---|---|---|
1 | A | en |
2 | Ä | de |
3 | A | de |
4 | O | en |
5 | O | de |
6 | Ö | de |
The letter mapping table
id | letter1(letterTable.id) | letter2(letterTable.id) |
---|---|---|
1 | 1 | 2 |
2 | 1 | 3 |
3 | 4 | 5 |
4 | 4 | 6 |
Would it be better to create a separate table for each alphabet?
Maybe there is some other architectural approach for this kind of letter matching? I would really appreciate it!
Advertisement
Answer
This can be achieved with a join that is restricted to the two languages you want to check:
select en.id as id_en, en.letter as letter_en, de.id as id_de, de.letter as letter_de from letter en join letter_mapping lm on lm.letter1 = en.id join letter de on de.id = lm.letter2 and de.language = 'de' where en.language = 'en';