Left join with default relation

后端 未结 1 890
挽巷
挽巷 2021-01-22 11:24

Need to find all words with their Italian translation, if Italian doesn\'t exist, then need with Spanish (default language). I can`t use more than one query, and where e

相关标签:
1条回答
  • 2021-01-22 11:53

    I'd join the words table on the translations table twice, once for each language:

    SELECT    w.id, 
              w.name,
              COALESCE(it.translation, es.translation) AS translation,
              COALESCE(it.language, es.language) AS language
    FROM      words w
    LEFT JOIN translation it ON w.id = it.word_id AND it.language = 'it'
    LEFT JOIN translation es ON w.id = es.word_id AND es.language = 'es'
    
    0 讨论(0)
提交回复
热议问题