Syntax error How to delete the duplicate values stored in reverse order from MySQL table?

How to delete the duplicate values stored in reverse order from MySQL table?



To understand this concept, we are using the data from table ‘Details_city’ as follows −

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

Now, the following query will delete the reverse duplicate values from details_city table −

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)
Updated on: 2020-06-22T12:35:57+05:30

320 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements