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

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

        <legend id='YYhhT'><style id='YYhhT'><dir id='YYhhT'><q id='YYhhT'></q></dir></style></legend>

        MySQL LEFT JOIN 3 个表

        时间:2023-06-25
      2. <small id='uf3Cy'></small><noframes id='uf3Cy'>

          <i id='uf3Cy'><tr id='uf3Cy'><dt id='uf3Cy'><q id='uf3Cy'><span id='uf3Cy'><b id='uf3Cy'><form id='uf3Cy'><ins id='uf3Cy'></ins><ul id='uf3Cy'></ul><sub id='uf3Cy'></sub></form><legend id='uf3Cy'></legend><bdo id='uf3Cy'><pre id='uf3Cy'><center id='uf3Cy'></center></pre></bdo></b><th id='uf3Cy'></th></span></q></dt></tr></i><div id='uf3Cy'><tfoot id='uf3Cy'></tfoot><dl id='uf3Cy'><fieldset id='uf3Cy'></fieldset></dl></div>
            <tfoot id='uf3Cy'></tfoot><legend id='uf3Cy'><style id='uf3Cy'><dir id='uf3Cy'><q id='uf3Cy'></q></dir></style></legend>
              <tbody id='uf3Cy'></tbody>

            • <bdo id='uf3Cy'></bdo><ul id='uf3Cy'></ul>

                  本文介绍了MySQL LEFT JOIN 3 个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 3 张桌子:

                  Persons (PersonID, Name, SS)
                  Fears (FearID, Fear)
                  Person_Fear (ID, PersonID, FearID)

                  现在我想列出所有与他们相关的恐惧的人(可以是多种恐惧,也可以是无恐惧).即使一个人没有与他们相关的恐惧,也必须显示人员表.

                  Now I'd like to list every person with whatever fear is linked to them (can be multiple fears but can also be none). The persons table has to be shown even if a person doesn't have a fear linked to them.

                  我想我需要做一个 LEFT JOIN,但我的代码似乎不起作用:

                  I think I need to do a LEFT JOIN, but my code doesn't seem to work:

                  SELECT persons.name, 
                         persons.ss, 
                         fears.fear 
                  FROM   persons 
                         LEFT JOIN fears 
                                ON person_fear.personid = person_fear.fearid 
                  

                  我在这里做错了什么?

                  推荐答案

                  您正在尝试将 Person_Fear.PersonID 加入 Person_Fear.FearID - 这并没有真正使感觉.你可能想要这样的东西:

                  You are trying to join Person_Fear.PersonID onto Person_Fear.FearID - This doesn't really make sense. You probably want something like:

                  SELECT Persons.Name, Persons.SS, Fears.Fear FROM Persons
                  LEFT JOIN Person_Fear
                      INNER JOIN Fears
                      ON Person_Fear.FearID = Fears.FearID
                  ON Person_Fear.PersonID = Persons.PersonID
                  

                  这通过中间表Person_FearPersons 连接到Fears.因为PersonsPerson_Fear 之间的join 是一个LEFT JOIN,你会得到所有Persons 记录.

                  This joins Persons onto Fears via the intermediate table Person_Fear. Because the join between Persons and Person_Fear is a LEFT JOIN, you will get all Persons records.

                  或者:

                  SELECT Persons.Name, Persons.SS, Fears.Fear FROM Persons
                  LEFT JOIN Person_Fear ON Person_Fear.PersonID = Persons.PersonID
                  LEFT JOIN Fears ON Person_Fear.FearID = Fears.FearID
                  

                  这篇关于MySQL LEFT JOIN 3 个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 MYSQL 创建一个随机数 下一篇:MySQL - 持久连接与连接池

                  相关文章

                    <bdo id='jxUan'></bdo><ul id='jxUan'></ul>

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