-3

次の結合を取得する方法

入力:

table1:     table2:
col1        Col1   col2 col3
A           A        1    2 
B           B        4    5
C   

出力:

col1   col2 col3 
A       1     2
B       4     5
c       -     -
4

6 に答える 6

0
select t1.col1, t2.col2, t2.col3
from table1 t1
left outer join table2 t2
on t1.col1 = t2.col1
于 2013-07-26T14:08:23.140 に答える
0
SELECT t1.col1, t2.col2, t2.col3
  FROM table1 t1
  LEFT JOIN table2 t2 ON t1.col1=t2.col1
;
于 2013-07-26T14:07:27.827 に答える
0

外部結合を行う必要があります

SELECT * 
  FROM table1 t1,
       table2 t2
WHERE t1.col1 = t2.col1(+)
于 2013-07-26T16:21:26.163 に答える
0

「-」を付けたくない場合は、このようなものかもしれません

SELECT t1.col1, coalesce(t2.col2,'-') as col2, coalesce(t2.col3,'-') as col3
FROM table1 t1
LEFT JOIN table2 t2 ON t1.col1=t2.col1
于 2013-07-26T14:10:51.667 に答える
0

私のsqlfiddleを参照してください

create table table1(
    col1 char(1)
  );

insert into table1 values('A');
insert into table1 values('B');
insert into table1 values('C');


create table table2(
    col1 char(1),
    col2 int,
    col3 int
  );

insert into table2 values('A',1,2);
insert into table2 values('B',4,5);


select 
  t1.col1, 
  coalesce(t2.col2,'-'), 
  coalesce(t2.col3,'-')
from 
  table1 t1
left join table2 t2 on t1.col1=t2.col1
;

http://sqlfiddle.com/#!2/bc768/2

于 2013-07-26T14:11:54.090 に答える