<legend id='Zqvml'><style id='Zqvml'><dir id='Zqvml'><q id='Zqvml'></q></dir></style></legend>
        <bdo id='Zqvml'></bdo><ul id='Zqvml'></ul>
        <tfoot id='Zqvml'></tfoot>
      1. <small id='Zqvml'></small><noframes id='Zqvml'>

      2. <i id='Zqvml'><tr id='Zqvml'><dt id='Zqvml'><q id='Zqvml'><span id='Zqvml'><b id='Zqvml'><form id='Zqvml'><ins id='Zqvml'></ins><ul id='Zqvml'></ul><sub id='Zqvml'></sub></form><legend id='Zqvml'></legend><bdo id='Zqvml'><pre id='Zqvml'><center id='Zqvml'></center></pre></bdo></b><th id='Zqvml'></th></span></q></dt></tr></i><div id='Zqvml'><tfoot id='Zqvml'></tfoot><dl id='Zqvml'><fieldset id='Zqvml'></fieldset></dl></div>
      3. 仅使用 MySQL 查询删除重复项?

        时间:2023-05-23
      4. <small id='MpYgA'></small><noframes id='MpYgA'>

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

              <tfoot id='MpYgA'></tfoot>

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

                    <tbody id='MpYgA'></tbody>
                • 本文介绍了仅使用 MySQL 查询删除重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个包含以下列的表格:

                  I have a table with the following columns:

                  URL_ID    
                  URL_ADDR    
                  URL_Time
                  

                  我想使用 MySQL 查询删除 URL_ADDR 列上的重复项.

                  I want to remove duplicates on the URL_ADDR column using a MySQL query.

                  不使用任何编程就可以做这样的事情吗?

                  Is it possible to do such a thing without using any programming?

                  推荐答案

                  考虑以下测试用例:

                  CREATE TABLE mytb (url_id int, url_addr varchar(100));
                  
                  INSERT INTO mytb VALUES (1, 'www.google.com');
                  INSERT INTO mytb VALUES (2, 'www.microsoft.com');
                  INSERT INTO mytb VALUES (3, 'www.apple.com');
                  INSERT INTO mytb VALUES (4, 'www.google.com');
                  INSERT INTO mytb VALUES (5, 'www.cnn.com');
                  INSERT INTO mytb VALUES (6, 'www.apple.com');
                  

                  我们的测试表现在包含的位置:

                  Where our test table now contains:

                  SELECT * FROM mytb;
                  +--------+-------------------+
                  | url_id | url_addr          |
                  +--------+-------------------+
                  |      1 | www.google.com    |
                  |      2 | www.microsoft.com |
                  |      3 | www.apple.com     |
                  |      4 | www.google.com    |
                  |      5 | www.cnn.com       |
                  |      6 | www.apple.com     |
                  +--------+-------------------+
                  5 rows in set (0.00 sec)
                  

                  那么我们就可以使用多表DELETE语法如下:

                  Then we can use the multiple-table DELETE syntax as follows:

                  DELETE t2
                  FROM   mytb t1
                  JOIN   mytb t2 ON (t2.url_addr = t1.url_addr AND t2.url_id > t1.url_id);
                  

                  ... 这将删除重复的条目,只留下基于 url_id 的第一个 url:

                  ... which will delete duplicate entries, leaving only the first url based on url_id:

                  SELECT * FROM mytb;
                  +--------+-------------------+
                  | url_id | url_addr          |
                  +--------+-------------------+
                  |      1 | www.google.com    |
                  |      2 | www.microsoft.com |
                  |      3 | www.apple.com     |
                  |      5 | www.cnn.com       |
                  +--------+-------------------+
                  3 rows in set (0.00 sec)
                  

                  <小时>

                  更新 - 对上述新评论的进一步补充:


                  UPDATE - Further to new comments above:

                  如果重复的 URL 格式不同,您可能需要应用 REPLACE() 函数删除 www.http:// 部分.例如:

                  If the duplicate URLs will not have the same format, you may want to apply the REPLACE() function to remove www. or http:// parts. For example:

                  DELETE t2
                  FROM   mytb t1
                  JOIN   mytb t2 ON (REPLACE(t2.url_addr, 'www.', '') = 
                                     REPLACE(t1.url_addr, 'www.', '') AND 
                                     t2.url_id > t1.url_id);
                  

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

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

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

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