Click here to Skip to main content
15,921,382 members

Comments by Member 13005867 (Top 6 by date)

Member 13005867 7-Apr-17 14:24pm View    
After I got the Solution from above query,I have tryed below query,But this did not gave me correct ans,Kindly Explain me your query how it is different from below query

select fromcity, tocity, min(distance) distance,Min(ID) ID
from table1
group by fromcity, tocity
Member 13005867 7-Apr-17 14:22pm View    
Thank U For Feasible Solution as it is not checking Record wise ,it is doing batch processing
Member 13005867 7-Apr-17 14:20pm View    
I have use for loop if Records are more,Check has to done on each Record wise.
Member 13005867 7-Apr-17 14:16pm View    
I have Just added ID column to you solution,Thank for the Solution.Modifyed Query is as Below.

select fromcity, tocity, min(distance) distance,Min(ID) ID
from
(
select case when fromcity > tocity then tocity else fromcity end fromcity,
case when fromcity > tocity then fromcity else tocity end tocity, distance,ID
from table1
) a
group by fromcity, tocity
Member 13005867 7-Apr-17 13:51pm View    
Question is Updated Now,Kindly Go through and Expected Result as Below

Expected Result :-Need to get only one Record Either Row1 or Row2 (No Duplicate Record) as Below

Row1
ID FromCity ToCity Distance
1 Hyderabad Bangalore 400

(OR)

Row2
ID FromCity ToCity Distance
2 Bangalore Hyderabad 400