1. <i id='5JKer'><tr id='5JKer'><dt id='5JKer'><q id='5JKer'><span id='5JKer'><b id='5JKer'><form id='5JKer'><ins id='5JKer'></ins><ul id='5JKer'></ul><sub id='5JKer'></sub></form><legend id='5JKer'></legend><bdo id='5JKer'><pre id='5JKer'><center id='5JKer'></center></pre></bdo></b><th id='5JKer'></th></span></q></dt></tr></i><div id='5JKer'><tfoot id='5JKer'></tfoot><dl id='5JKer'><fieldset id='5JKer'></fieldset></dl></div>
    • <bdo id='5JKer'></bdo><ul id='5JKer'></ul>
    <tfoot id='5JKer'></tfoot>

  2. <legend id='5JKer'><style id='5JKer'><dir id='5JKer'><q id='5JKer'></q></dir></style></legend>

    <small id='5JKer'></small><noframes id='5JKer'>

      具有默认关系的左连接

      Left join with default relation(具有默认关系的左连接)
        <bdo id='dlejg'></bdo><ul id='dlejg'></ul>
        <legend id='dlejg'><style id='dlejg'><dir id='dlejg'><q id='dlejg'></q></dir></style></legend>

            <small id='dlejg'></small><noframes id='dlejg'>

              1. <i id='dlejg'><tr id='dlejg'><dt id='dlejg'><q id='dlejg'><span id='dlejg'><b id='dlejg'><form id='dlejg'><ins id='dlejg'></ins><ul id='dlejg'></ul><sub id='dlejg'></sub></form><legend id='dlejg'></legend><bdo id='dlejg'><pre id='dlejg'><center id='dlejg'></center></pre></bdo></b><th id='dlejg'></th></span></q></dt></tr></i><div id='dlejg'><tfoot id='dlejg'></tfoot><dl id='dlejg'><fieldset id='dlejg'></fieldset></dl></div>
                <tfoot id='dlejg'></tfoot>

                  <tbody id='dlejg'></tbody>
                本文介绍了具有默认关系的左连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                需要找到所有带有意大利语翻译的单词,如果意大利语不存在,则需要使用西班牙语(默认语言).我不能使用多个查询,并且条件存在(技术限制)

                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 exists condition(technical limitations)

                id|name
                -------
                 1|Dog
                 2|Cat
                

                翻译

                id|word_id|translation|language
                -------------------------------
                 1|      1|      Perro|es
                 2|      1|      Cane |it
                 3|      2|      Gatto|es
                

                结果:

                id|name|translation|language
                 1| Dog|       Cane|it
                 2| Cat|      Gatto|es
                

                <小时>

                SELECT * FROM words LEFT JOIN translation ON words.id = translation.word_id WHERE language = 'it' OR (language = 'es' AND NOT EXISTS(SELECT * FROM translation WHERE word_id = words.id AND language = 'it'))
                

                此代码返回我需要的所有内容,但我无法在我的情况下使用 where exists 条件

                This code return all I need, but I can't use where exists conditions in my situation

                推荐答案

                我会在 translations 表中加入 words 表两次,每种语言一次:

                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'
                

                这篇关于具有默认关系的左连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
              2. <i id='C2WPO'><tr id='C2WPO'><dt id='C2WPO'><q id='C2WPO'><span id='C2WPO'><b id='C2WPO'><form id='C2WPO'><ins id='C2WPO'></ins><ul id='C2WPO'></ul><sub id='C2WPO'></sub></form><legend id='C2WPO'></legend><bdo id='C2WPO'><pre id='C2WPO'><center id='C2WPO'></center></pre></bdo></b><th id='C2WPO'></th></span></q></dt></tr></i><div id='C2WPO'><tfoot id='C2WPO'></tfoot><dl id='C2WPO'><fieldset id='C2WPO'></fieldset></dl></div>
              3. <legend id='C2WPO'><style id='C2WPO'><dir id='C2WPO'><q id='C2WPO'></q></dir></style></legend>

                <small id='C2WPO'></small><noframes id='C2WPO'>

                    <tbody id='C2WPO'></tbody>
                  <tfoot id='C2WPO'></tfoot>
                      <bdo id='C2WPO'></bdo><ul id='C2WPO'></ul>