Search code examples
uniquerecords

find the unique record on two columns in oracle


i have a table like

from to distance Bangalore Hyderabad 1000 Hyderabad Bangalore 1000

here Hyderabad to Bangalore and Bangalore to Hyderabad both are having same distance.so i want first record if the data comes like this...


Solution

  • You could just write a simple where clause which defines your need.

    Eg: select distance from TABLE_NAME where ( ("from" = 'Bangalore' and "to" = 'Hyderabad') or ("from" = 'Hyderabad' and "to" ='Bangalore') ) and rownum <= 1

    http://sqlfiddle.com/#!4/0fc987/4