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
Answer / nihar meher
select distinct greatest(source,destination),least(source,destination) from tablename;
| Is This Answer Correct ? | 3 Yes | 1 No |
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 |
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 |
Which join condition can be specified using on clause?
What is rank dense_rank and partition in sql?
What is primary key in db?
Is it possible to use LONG columns in WHERE clause or ORDER BY?
What is interval partition?
what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba
List and explain the different types of join clauses supported in ansi-standard sql?
What version is sql?
Can we join 3 tables in sql?
Can we enter data in a table in design view?
How to display Row Number with Records in Oracle SQL Plus?
Which tcp/ip port does sql server run?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)