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?

Answers were Sorted based on User's Feedback



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

Answer / nihar meher

select distinct greatest(source,destination),least(source,destination) from tablename;

Is This Answer Correct ?    3 Yes 1 No

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

Answer / ajitnayak

select distinct source,destination,distance from dist_tab where source > destination
minus
select distinct source,destination,distance from dist_tab where source < destination

Is This Answer Correct ?    0 Yes 0 No

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

Answer / 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

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

Answer / deepak

select source, destination, distance from Distance_rcd where source>destination
union select destination, source, distance from Distance_rcd where source<destination

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More SQL PLSQL Interview Questions

Why truncate is faster than delete?

0 Answers  


what is rdbms? : Sql dba

0 Answers  


What does <> sql mean?

0 Answers  


What trigger means?

0 Answers  


What is faster join or subquery?

0 Answers  






What can you do with pl sql?

0 Answers  


Explain correlated query work?

0 Answers  


What are the parameter modes supported by pl/sql?

0 Answers  


1 SELECT a.field1, b.field2, c.field3, d.field4 2 FROM atable a, atable b, ctable c, dtable d 3 ? 4 ORDER BY 1 What is the minimum number of joins that must be specified on line 3 in the sample code above to properly link the tables? Notice that the table "atable" is aliased twice: once as "a" and once as "b." 1. One join 2. Two joins 3. Three joins 4. Four joins 5. Five joins

6 Answers   Sonata,


Explain what is dbms?

0 Answers  


select sal from emp group by sal

3 Answers   TCS,


How many rows can sqlite handle?

0 Answers  


Categories