1

i have a table like below i want to get unique values.

from_st     to_st       fare
---------------------------
Bangalore   Hyderabad   600
Hyderabad   Bangalore   600
Bangalore   chennai     500
chennai     Bangalore   500
Bangalore   noida       1500
noida       Banagalore  1500
bangalore   delhi       3000
bangalore   pune        2000

i need data like Bangalore to Hyderabad and Hyderabad to Bangalore are duplicates. so i want only one records among them.

desired output:

from_st     to_st       fare
---------------------------
Bangalore   Hyderabad   600
Bangalore   chennai     500
Bangalore   noida       1500
bangalore   delhi       3000
bangalore   pune        2000
Florin Ghita
  • 17,525
  • 6
  • 57
  • 76
prasad
  • 31
  • 4

1 Answers1

1

You may do this:

 select distinct least(from_st, to_st), greatest(from_st, to_st), fare
 from your table;
Florin Ghita
  • 17,525
  • 6
  • 57
  • 76