<small id='1Lkvt'></small><noframes id='1Lkvt'>

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

      <legend id='1Lkvt'><style id='1Lkvt'><dir id='1Lkvt'><q id='1Lkvt'></q></dir></style></legend>
      <tfoot id='1Lkvt'></tfoot>
        <bdo id='1Lkvt'></bdo><ul id='1Lkvt'></ul>
    1. 从一张表中选择不在另一张表中

      时间:2023-06-02
      <i id='k2GGj'><tr id='k2GGj'><dt id='k2GGj'><q id='k2GGj'><span id='k2GGj'><b id='k2GGj'><form id='k2GGj'><ins id='k2GGj'></ins><ul id='k2GGj'></ul><sub id='k2GGj'></sub></form><legend id='k2GGj'></legend><bdo id='k2GGj'><pre id='k2GGj'><center id='k2GGj'></center></pre></bdo></b><th id='k2GGj'></th></span></q></dt></tr></i><div id='k2GGj'><tfoot id='k2GGj'></tfoot><dl id='k2GGj'><fieldset id='k2GGj'></fieldset></dl></div>
    2. <legend id='k2GGj'><style id='k2GGj'><dir id='k2GGj'><q id='k2GGj'></q></dir></style></legend>
        <bdo id='k2GGj'></bdo><ul id='k2GGj'></ul>
          <tbody id='k2GGj'></tbody>

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

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

                本文介绍了从一张表中选择不在另一张表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试查找一个表中而不是另一个表中的行,两个表都在不同的数据库中,并且在我用来匹配的列上也有不同的列名.

                I'm trying to find the rows that are in one table but not another, both tables are in different databases and also have different column names on the column that I'm using to match.

                我有一个查询,代码如下,我认为它可能有效,但速度太慢:

                I've got a query, code below, and I think it probably works but it's way too slow:

                SELECT `pm`.`id`
                FROM `R2R`.`partmaster` `pm`
                WHERE NOT EXISTS (
                    SELECT * 
                    FROM `wpsapi4`.`product_details` `pd`
                    WHERE `pm`.`id` = `pd`.`part_num`
                )
                

                因此查询尝试执行如下操作:

                So the query is trying to do as follows:

                从 R2R.partmaster 数据库中选择 wpsapi4.product_details 数据库中没有的所有 id.我匹配的列是 partmaster.id &product_details.part_num

                Select all the ids from the R2R.partmaster database that are not in the wpsapi4.product_details database. The columns I'm matching are partmaster.id & product_details.part_num

                推荐答案

                扩展 Sjoerd 的反连接,您还可以使用易于理解的 SELECT WHERE X NOT IN (SELECT) 模式.

                Expanding on Sjoerd's anti-join, you can also use the easy to understand SELECT WHERE X NOT IN (SELECT) pattern.

                SELECT pm.id FROM r2r.partmaster pm
                WHERE pm.id NOT IN (SELECT pd.part_num FROM wpsapi4.product_details pd)
                

                请注意,您只需要在保留字、带空格的名称等上使用 ` 反引号,而不是普通列名.

                Note that you only need to use ` backticks on reserved words, names with spaces and such, not with normal column names.

                在 MySQL 5+ 上,这种查询运行得非常快.
                在 MySQL 3/4 上它很慢.

                On MySQL 5+ this kind of query runs pretty fast.
                On MySQL 3/4 it's slow.

                确保您对相关字段有索引
                你需要在 pm.idpd.part_num 上有一个索引.

                这篇关于从一张表中选择不在另一张表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在两个字段上使用 group by 并在 SQL 中计数 下一篇:在 windows xampp 上在哪里更改 lower_case_table_names=2 的值

                相关文章

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

                1. <legend id='xiJuQ'><style id='xiJuQ'><dir id='xiJuQ'><q id='xiJuQ'></q></dir></style></legend>

                  1. <small id='xiJuQ'></small><noframes id='xiJuQ'>

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