Input As
=====================
city1 city2 distance
=====================
Raipur Goa 500
Goa Raipur 500
Manik Jamui 200
Jamui Manik 200
Noida Pune 100
Output:
=====================
city1 city2 distance
=====================
Raipur Goa 500
Jamui Manik 200
Noida Pune 100
For Raipur and Goa there are 2 rows and the same for Manik and Jamui in input data. In the output, it should fetch only 1 row. How to create SQL query for the above input to get the required output.
>Solution :
Try this:
select distinct greatest(city1, city2) as city1, least(city1, city2) as city2, distance
from Input