I am working on a mySQL issue. I want to setup a translation system, where keys (placeholders) are saved in the tblkeys and the translations are stored in tbltranslations.
Every user in the system has a language setting and I want the system to use English, when the translation in the user’s language is not available.
SELECT * FROM tblkeys, tbltranslations
WHERE
tblkeys.fiproject = 1
AND tbltranslations.fiproject = tblkeys.fiproject
AND tbltranslations.fikey = tblkeys.idkey
AND (tbltranslations.dtlanguage = 'de' OR tbltranslations.dtlanguage = 'en')
GROUP BY tblkeys.idkey
Here I used a simply OR for demonstrating what I mean. The problem, I want the system to prefer de, but if not available use en as dtlanguage.
How could I manage that?
Thank’s in advance!
You can use two left joins. One joining all DE strings, one for joining all EN strings and then add an IFNULL(de.text, en.text) in your select