sql - join 2 tables using oracle -
there 2 tables data below. column 'id' available in both tables. can please me how desired output.
table 1:
id ind 101 y 102 n table 2:
id cd 101 101 b 101 c 101 d 102 desired output:
id cd ind 101 y 101 b 101 c 101 d 102 n
what have here join want display value of ind on first cd of each id. can row_number() window function in case expression:
select t1.id, t2.cd, case rn when 1 t1.ind else null end ind table1 t1 join (select id, cd, row_number() on (partition ind order cd asc) rn table2) t2 on t1.id = t2.id
Comments
Post a Comment