如何按反向顺序从 MySQL 表格中删除重复值?


为理解此概念,我们如下所示使用表‘Details_city’ 中的数据 -

mysql> Select * from details_city;
+--------+--------+
| City1  | City2  |
+--------+--------+
| Delhi  | Nagpur |
| Delhi  | Mumbai |
| Nagpur | Delhi  |
| Katak  | Delhi  |
| Delhi  | Katak  |
+--------+--------+
5 rows in set (0.00 sec)

现在,以下查询将从 details_city 表格中删除反向重复值:-

mysql> Select a.city1,a.city2 from details_city a WHERE a.city1 <= a.city2;
+-------+--------+
| city1 | city2  |
+-------+--------+
| Delhi | Nagpur |
| Delhi | Mumbai |
| Delhi | Katak  |
+-------+--------+
3 rows in set (0.06 sec)

更新时间: 22-Jun-2020

287 人浏览

启动你的 职业

通过完成课程获得认证

开始
广告