sql - How to list all pairs of location with same area from the table in Oracle? -


i have been trying find answer question.

list pairs of locations have same area. result should list (location name 1, location name 2, location area) location name 1 , location name 2 have same location area. pair should appear once in output.

so table can 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), , on.

update:

i table first name, second name , location area pratik's solution. but, doesn't give value in table.

what if this?

select t_1.loc_name name1, t_2.loc_name name2, t_1.loc_area location t_1, location t_2 t_1.loc_area = t_2.loc_area , t_1.loc_name<>t_2.loc_name order t_1.loc_name 

i list of probable combinations (similar rebika's solution below). how remove duplicates 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.

try this,

select a.loc_name, b.loc_name, a.loc_area   location a, location b  a.loc_area = b.loc_area    , a.loc_name != b.loc_name    , a.loc_id < b.loc_id; 
  • first condition ensures records same loc_area joined.
  • second condition ensures loc_name not joined itself.
  • third condition ensures 1 combination of loc_name returned.

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -