15,921,382 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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
Member 13005867
6-Apr-17 10:11am
View
We will Get the Distinct values with Columns FromCity,ToCity,Distance But Expected Result is With ID Column of the Table,When ID is used in above Query we will get Two Rows in Result Set
Show More