source destination distance
chennai bangalore 500
bangalore chennai 500
hyd delhi 1000
delhi hyd 1000
bangalore hyd 800

Here chennai to bangalore and bangalore to chennai is same distance. and hyd and delhi also same criteria.
Based on the distance i want to display only one row using sql query?

Answer Posted / sushma ajay

select source, destination, distance from(
select source,destination,lag(source) over (order by distance) oldsrc,distance
from traveldist)
where nvl(destination,'@') <> nvl(oldsrc,'@');

Is This Answer Correct ?    5 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which command is used to delete a trigger?

769


What are tables in sql?

544


what are the differences between get and post methods in form submitting. Give the case where we can use get and we can use post methods? : Sql dba

669


What is the source code of a program?

503


Are stored procedures faster than dynamic sql?

528






How you can copy a file to file content and file to pl/sql table in advance pl/sql?

618


Does sql require a server?

524


Why sql query is slow?

576


What is a clob in sql?

562


What is a primary key called that is made up of more than one field?

787


What are pl sql procedures?

510


How you improve the performance of sql*loader? : aql loader

573


Which join is like an inner join?

522


What is the difference between syntax error and runtime error?

612


Explain character-manipulation functions?

623