반응형
/********************************************************************************************
-- Title : [PGS9.2] Usage of JOIN ~ USING()
-- Reference : dbrang.tistory.com
-- Key word : postgresql join using 조인
********************************************************************************************/
-- Initiate Table
drop table ttt_1;
drop table ttt_2;
 
-- Create Table
create table ttt_1
( a int
, b int
);
 
create table ttt_2
( a int
, c int
);
 
-- Insert Data
insert into ttt_1 values (1,1);
insert into ttt_1 values (2,2);
insert into ttt_1 values (3,3);
insert into ttt_1 values (4,4);
insert into ttt_1 values (5,5);
 
insert into ttt_2 values (2,22);
insert into ttt_2 values (3,33);
insert into ttt_2 values (4,44);
insert into ttt_2 values (5,55);
insert into ttt_2 values (6,66);
 
-- Select Table
select *
from ttt_1 a
full outer join ttt_2 b
on a.a = b.a;
 
-- Select Join with INNER_USING()
-- Not print duplicate matched column in ON clause.
select *
from ttt_1 a
inner join ttt_2 b USING(a);
 a | b | c
---+---+----
 2 | 2 | 22
 3 | 3 | 33
 4 | 4 | 44
 5 | 5 | 55
 
-- Select Join with INNER~ON
-- Print duplicate matched column in ON clause.
select *
from ttt_1 a
inner join ttt_2 b 
on a.a = b.a;
 a | b | a | c
---+---+---+----
 2 | 2 | 2 | 22
 3 | 3 | 3 | 33
 4 | 4 | 4 | 44
 5 | 5 | 5 | 55
반응형

+ Recent posts