1. <tfoot id='zbgsf'></tfoot>

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

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

        你如何在 mysql 中加入同一个表,两次?

        时间:2023-08-17
          <tbody id='fAcxq'></tbody>

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

        • <tfoot id='fAcxq'></tfoot>

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

              <bdo id='fAcxq'></bdo><ul id='fAcxq'></ul>
            • <legend id='fAcxq'><style id='fAcxq'><dir id='fAcxq'><q id='fAcxq'></q></dir></style></legend>

                  本文介绍了你如何在 mysql 中加入同一个表,两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有两张桌子.一个(域)有域 id 和域名(dom_id、dom_url).

                  I have 2 tables. One (domains) has domain ids, and domain names (dom_id, dom_url).

                  另一个包含实际数据,其中 2 列需要 TO 和 FROM 域名.所以我有 2 列 rev_dom_from 和 rev_dom_for,它们都存储域表中的域名 id.

                  the other contains actual data, 2 of which columns require a TO and FROM domain names. So I have 2 columns rev_dom_from and rev_dom_for, both of which store the domain name id, from the domains table.

                  简单.

                  现在我需要在网页上实际显示两个域名.我知道如何通过 LEFT JOIN 域 ON review.rev_dom_for = domain.dom_url 查询来显示一个或另一个,然后您回显 dom_url,这将回显 rev_dom_for 列中的域名.

                  Now I need to actually display both domain names on the webpage. I know how to display one or the other, via the LEFT JOIN domains ON reviews.rev_dom_for = domains.dom_url query, and then you echo out the dom_url, which would echo out the domain name in the rev_dom_for column.

                  但是我如何让它在 dom_rev_from 列中与第二个域名相呼应?

                  But how would I make it echo out the 2nd domain name, in the dom_rev_from column?

                  推荐答案

                  你会使用另一个连接,大致如下:

                  you'd use another join, something along these lines:

                  SELECT toD.dom_url AS ToURL, 
                      fromD.dom_url AS FromUrl, 
                      rvw.*
                  
                  FROM reviews AS rvw
                  
                  LEFT JOIN domain AS toD 
                      ON toD.Dom_ID = rvw.rev_dom_for
                  
                  LEFT JOIN domain AS fromD 
                      ON fromD.Dom_ID = rvw.rev_dom_from
                  

                  编辑:

                  您所做的只是多次加入表格.查看帖子中的查询:它从评论表(别名为 rvw)中选择值,该表为您提供了对域表的 2 个引用(一个 FOR 和一个 FROM).

                  All you're doing is joining in the table multiple times. Look at the query in the post: it selects the values from the Reviews tables (aliased as rvw), that table provides you 2 references to the Domain table (a FOR and a FROM).

                  此时,将 Domain 表左连接到 Reviews 表是一件简单的事情.一次(别名为 toD)用于 FOR,第二次(别名为 fromD)用于 FROM.

                  At this point it's a simple matter to left join the Domain table to the Reviews table. Once (aliased as toD) for the FOR, and a second time (aliased as fromD) for the FROM.

                  然后在 SELECT 列表中,您将从 DOMAIN 表的两个 LEFT JOINS 中选择 DOM_URL 字段,通过引用域表的每个联接的表别名来引用它们,并将它们别名为 ToURL 和 FromUrl.

                  Then in the SELECT list, you will select the DOM_URL fields from both LEFT JOINS of the DOMAIN table, referencing them by the table alias for each joined in reference to the Domains table, and alias them as the ToURL and FromUrl.

                  有关 SQL 中别名的更多信息,请阅读此处.

                  For more info about aliasing in SQL, read here.

                  这篇关于你如何在 mysql 中加入同一个表,两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 MySQL 触发器中引发阻止表更新的错误 下一篇:在 MySQL 中相交的替代方法

                  相关文章

                  最新文章

                    <legend id='9VMpQ'><style id='9VMpQ'><dir id='9VMpQ'><q id='9VMpQ'></q></dir></style></legend>

                      <small id='9VMpQ'></small><noframes id='9VMpQ'>

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