I have been trying to find the answer to this question.
List all pairs of locations that have same area. The result should list (location name 1, location name 2, location area)
where location name 1
and location name 2
have same location area
. This pair should appear only once in the output.
So the table can look like this:
(Loc_id, Loc_name, Loc_area)
(1, ABC, 60)
(2, ZXY, 50)
(3, DEF, 60)
(4, YUM, 60)
(5, ZUM, 50)
Pairs: (ABC,DEF,60)
, (ZXY,ZUM,50)
, (ABC,YUM,60)
, (DEF,ZUM,60)
, and so on.
UPDATE:
I get a table with first name, second name and location area with Pratik's solution. But, it doesn't give any value in this table.
what if I do this?
select t_1.Loc_name name1, t_2.loc_name name2, t_1.loc_area
from Location t_1, Location t_2
where t_1.loc_area = t_2.loc_area and t_1.loc_name<>t_2.loc_name
Order by t_1.Loc_name
I get the list of all probable combinations (similar to Rebika's solution below). But now how do i remove duplicates from this list?
I don't want
name1 name2 loc_area
ABC DEF 60
DEF ABC 60
I want
name1 name2 loc_area
ABC DEF 60
ABC YUM 60
DEF YUM 60
.
.
.
Thanks.