Table1 Table2
Age / Name Name / School
10 / SJ SJ / PNU
20 / MK MK / HB
30 / LH LH / null
40 / MS MK / CU
MS / null
이렇게 두개의 테이블이 있을때
조인을 하여 값을 보여주려고 하는데요
select a.Name ||'-'||a.Age as Profile , b.School from Table1 a , Table2 b 인데..
LH랑 MS는 School이 없어서 null로 나오게 하고싶은데..잘 안되네요..
Table1 에 있는 모든 Name값은 표시되었으면 좋겠고 그 값에 대응되는 Table2번에 School을 나오게 하고싶습니다.
null은 null로 하고...근데 데이터가 중복해서 나오기도 하고..엉망진창이네요..
답변 부탁드립니다~~
기대결과
Profile School
SJ-10 PNU
MK-20 HB,CU
LH-30 null
MS-40 null
with t (age, name) as ( select 10 , 'SJ' from dual union all select 20 , 'MK' from dual union all select 30 , 'LH' from dual union all select 40 , 'MS' from dual ), t2 (name,school) as ( select 'SJ','PNU' from dual union all select 'MK','HB' from dual union all select 'LH',null from dual union all select 'MK','CU' from dual union all select 'MS',null from dual) select a.name ||'-'||a.age as profile , b.school from ( select age, name from t) a,(select name,wm_concat(school) school from t2 group by name) b where a.name = b.name order by age