mysql> desc test;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| site | varchar(100) | NO | MUL | | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
| 4 | http://www.baidu.com |
| 5 | http://www.huwei.com |
+----+------------------------+
5 rows in set (0.00 sec)
mysql> delete from a
-> using test as a, test as b
-> where (a.id > b.id)
-> and (a.site = b.site);
Query OK, 2 rows affected (0.12 sec)
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
+----+------------------------+
3 rows in set (0.00 sec)
mysql> delete from a
-> using test as a, test as b
-> where (a.id < b.id)
-> and (a.site = b.site);
Query OK, 2 rows affected (0.12 sec)
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 2 | http://www.hao123.com |
| 4 | http://www.baidu.com |
| 5 | http://www.huwei.com |
+----+------------------------+
3 rows in set (0.00 sec)
mysql> SELECT a.*
-> FROM test a, test b
-> WHERE a.id > b.id
-> AND (a.site = b.site);
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 3 | http://www.huwei.com |
+----+------------------------+
2 rows in set (0.00 sec)
mysql> alter ignore table test add unique index ukey (site);
Query OK, 5 rows affected (0.46 sec)
Records: 5 Duplicates: 2 Warnings: 0
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
+----+------------------------+
3 rows in set (0.00 sec)
mysql> alter table test drop index ukey;
Query OK, 3 rows affected (0.37 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> create table test_new as select * from test group by site;
Query OK, 3 rows affected (0.19 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test |
| test_new |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
| 4 | http://www.baidu.com |
| 5 | http://www.huwei.com |
+----+------------------------+
5 rows in set (0.00 sec)
mysql> select * from test_new order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
+----+------------------------+
3 rows in set (0.00 sec)
mysql> rename table test to test_old, test_new to test;
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test |
| test_old |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from test order by id;
+----+------------------------+
| id | site |
+----+------------------------+
| 1 | http://www.baidu.com |
| 2 | http://www.hao123.com |
| 3 | http://www.huwei.com |
+----+------------------------+
3 rows in set (0.00 sec)
mysql> desc test;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| id | int(11) unsigned | NO | | 0 | |
| site | varchar(100) | NO | | | |
+-------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2018-08-06 银行卡信用卡的支付测试