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 |
What is server name sql?
Which query operators in sql is used for pattern matching?
how to check the 3rd max salary from an employee table? One of the queries used is as follows: select sal from emp a where 3=(select count(distinct(sal)) from emp b where a.sal<=b.sal). Here in the sub query "select count(distinct(sal)) from emp b where a.sal<=b.sal" or "select count(distinct(sal)) from emp b where a.sal=b.sal" should reveal the same number of rows is in't it? Can any one here please explain me how is this query working perfectly. However, there is another query to get the 3rd highest of salaries of employees that logic I can understand. Pls find the query below. "select min(salary) from emp where salary in(select distinct top 3 salary from emp order by salary desc)" Please explain me how "select sal from emp a where 3=(select count(distinct(sal)) from emp b where a.sal<=b.sal)" works source:http://www.allinterview.com/showanswers/33264.html. Thanks in advance Regards, Karthik.
What is difference between Procedures and Functions ?
What is nested table in pl sql?
Can we insert data into view?
Mention what plvcmt and plvrb does in pl/sql?
Can a table have two primary keys?
what is offset-fetch filter in tsql? : Transact sql
How are functions and procedures called in PL/SQL?
Why do we create stored procedures & functions in pl/sql and how are they different?
Can we use view in stored procedure?