Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL query for below data input

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this:

select distinct greatest(city1, city2) as city1, least(city1, city2) as city2, distance
from Input
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading