Log in

View Full Version : distinct rows based on combination of columns



aravindhan_3
08-07-2015, 03:29 AM
Hi,
I have the table for train journey col 1 - From destinationn col 2 - To Destination col C distance
now i want to write a query to ge the unique journeys that are available?
for example there will be rows for
From - London To Paris
From Paris To London,
basically both are same trip, so wanted to get just one in my result?
how do i write a query to get this
Regards
Arvind

jdej66339oa
08-16-2015, 08:05 PM
Aravimdan_3. The distinct only works when the 2 columns are unique. Distinct is made to avoid duplicate, but in order to work all the selected combined columns must be unique. Therefore London to Paris is unique within its own row, and Paris to London is unique with its own row. GPS systems uses kinda the same system but in order to work you must specify the From Location to Destination Location. If the trips a round trip you have then to invert the locations in order to work, cuz your first trip might be shorter then your returning trip and your returning trip might take you to different roads.

your locations are stored in one table only?