• <legend id='lb3F5'><style id='lb3F5'><dir id='lb3F5'><q id='lb3F5'></q></dir></style></legend>

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

      1. 如何删除MySQL表中的重复项

        时间:2023-05-23

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

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

                  <tbody id='lqWQM'></tbody>
              • <legend id='lqWQM'><style id='lqWQM'><dir id='lqWQM'><q id='lqWQM'></q></dir></style></legend>

                <i id='lqWQM'><tr id='lqWQM'><dt id='lqWQM'><q id='lqWQM'><span id='lqWQM'><b id='lqWQM'><form id='lqWQM'><ins id='lqWQM'></ins><ul id='lqWQM'></ul><sub id='lqWQM'></sub></form><legend id='lqWQM'></legend><bdo id='lqWQM'><pre id='lqWQM'><center id='lqWQM'></center></pre></bdo></b><th id='lqWQM'></th></span></q></dt></tr></i><div id='lqWQM'><tfoot id='lqWQM'></tfoot><dl id='lqWQM'><fieldset id='lqWQM'></fieldset></dl></div>
                  <tfoot id='lqWQM'></tfoot>
                1. 本文介绍了如何删除MySQL表中的重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我向客户提供了以下查询以删除重复的电话号码.MSSQL 数据库中的记录,但现在他们也需要在 MySQL 上执行此操作,并且他们报告 MySQL 抱怨查询的格式.我已经为我的代码示例包含了一个带有重复项的测试表的设置,但实际的删除查询才是最重要的.

                  I've given a client the following query to delete duplicate phone no. records in an MSSQL database, but now they need to also do it on MySQL, and they report that MySQL complains about the format of the query. I've included the setup of a test table with duplicates for my code sample, but the actual delete query is what counts.

                  我是在无知和紧急的情况下问这个问题的,因为我还在忙于下载和安装 MySQL,在此期间也许有人可以提供帮助.

                  I'm asking this in ignorance and urgency, as I am still busy downloading and installing MySQL, and just maybe somebody can help in the mean time.

                   create table bkPhone
                   (
                       phoneNo nvarchar(20),
                       firstName nvarchar(20),
                       lastName nvarchar(20)
                   )
                   GO
                  
                   insert bkPhone values('0783313780','Brady','Kelly')
                   insert bkPhone values('0845319792','Mark','Smith')
                   insert bkPhone values('0834976958','Bill','Jones')
                   insert bkPhone values('0845319792','Mark','Smith')
                   insert bkPhone values('0828329792','Mickey','Mouse')
                   insert bkPhone values('0834976958','Bill','Jones')
                  
                   alter table bkPhone add phoneId int identity
                  
                   delete from bkPhone
                   where phoneId not in
                   (
                       select min(phoneId)
                       from bkPhone
                       group by phoneNo,firstName,lastName
                       having  count(*) >= 1
                   )
                  

                  推荐答案

                  通向罗马的方法很多.这是一.它非常快.所以你可以将它与大型数据库一起使用.不要忘记 indeces.诀窍是:使 phoneNo 唯一并使用ignore".

                  Many ways lead to Rome. This is one. It is very fast. So you can use it with big databases. Don't forget the indeces. The trick is: make phoneNo unique and use "ignore".

                  drop table if exists bkPhone_template;
                  create table bkPhone_template (
                           phoneNo varchar(20),
                           firstName varchar(20),
                           lastName varchar(20)
                   );
                  
                  insert into bkPhone_template values('0783313780','Brady','Kelly');
                   insert into bkPhone_template values('0845319792','Mark','Smith');
                   insert into bkPhone_template values('0834976958','Bill','Jones');
                   insert into bkPhone_template values('0845319792','Mark','Smith');
                   insert into bkPhone_template values('0828329792','Mickey','Mouse');
                   insert into bkPhone_template values('0834976958','Bill','Jones');
                  
                  drop table if exists bkPhone;
                  create table bkPhone like bkPhone_template;
                  alter table bkPhone add unique (phoneNo);
                  
                  insert  ignore into bkPhone (phoneNo,firstName,lastName) select phoneNo,firstName,lastName from bkPhone_template;
                  
                  drop table bkPhone_template;
                  

                  如果数据表已经存在,那么您只需要使用以下插入忽略选择运行创建表选择.最后,您必须运行一些表重命名语句.仅此而已.

                  If the data table already exists, then you only have to run a create table select with a following insert ignore select. At the end you have to run some table renaming statements. That's all.

                  此解决方法比删除操作快得多.

                  This workaround is much,much faster then a delete operation.

                  这篇关于如何删除MySQL表中的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 sql 转义的动态 mysql 查询与准备好的语句一样安全吗? 下一篇:MYSQL ORDER BY CASE 问题

                  相关文章

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

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

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

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

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