And second I am trying to understand if it is possible to set for example english as the default language and when content for language with id 3 (Italian) is not present the default should fallback in as a result like this:(Language) (Country name)English Ireland in EnglishGerman Ireland in GermanItalian Ireland in English #please note language id is 3 -> Italian.推荐答案好,因此以下查询可能无需子查询而是使用联接来完成.我相信查询优化器可以做到这一点,但是我不太确定.okay, so the following query can probably be done without a subquery but with a join instead. I'd trust the query optimizer does this, but I wouldn't be too sure.SELECT l.name as language, (SELECT cl.name FROM country_languages cl WHERE cl.country_id=[the wanted country id] ORDER BY cl.language_id=l.id DESC, cl.language_id=1 DESC LIMIT 1) as country_nameFROM languages l在此版本中,language_id 1用作首选的后备,您可能会以类似的方式添加更多语言.使用FIND_IN_SET代替二阶条件也可以(FIND_IN_SET(cl.language_id,'1,2,3') DESC或您想要的任何顺序).In this version language_id 1 is used as the prefered fallback, you could probably add more languages in a similar manner. Using FIND_IN_SET instead as a second order criterion would work as well (FIND_IN_SET(cl.language_id,'1,2,3') DESC or whatever order you'd prefer).当然,此查询现在针对的是固定的country_id.可以以类似的方式将其扩展到具有另一个联接的多个国家:Of course this query right now is for a fixed country_id. It could be extended in a similar manner for multiple countries with another join:SELECT l.name as language, (SELECT cl.name FROM country_languages cl WHERE cl.country_id=c.id ORDER BY cl.language_id=l.id DESC, cl.language_id=1 DESC LIMIT 1) as country_nameFROM countries cJOIN languages l子查询的另一种选择是两次加入country_languages,然后选择第一个不为null的(可能是更干净的解决方案之一):an alternative to subqueries would be to join the country_languages twice, and just select the first one not being null (which is probably one of the cleaner solutions):SELECT l.name as language, COALESCE(first.name, second.name) as country_nameFROM countries cJOIN languages lLEFT JOIN country_languages first ON (first.country_id=c.id AND first.language_id=l.id)LEFT JOIN country_languages second ON (second.country_id=c.id AND second.language_id=1)如果语言ID 1是您的后备语言.还可以扩展它以提供多种后备语言...If language id 1 is your fallback language. This can be expanded as well to provide multiple fallback languages ... 这篇关于缺少语言后备的mysql翻译表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!