database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 4788 게시물 읽기
No. 4788
Outer Join 예입니다.
작성자
노사모하나(oslim73)
작성일
2003-07-15 21:42
조회수
1,814

작년 이맘때쯤.. PostgreSQL의 느린 Update를 불평했던.. 한 코더입니다.

하지만 점점더.. SQL92 표준이란 것을 알게되면서..

적응이 되어가고 있습니다...

 

일하다... 오라클의 Outer Join을 SQL92 표준으로 바꾸어 보았는데..

올려봅니다.

테스트는 mmdb인 알티베이스로 했지만 PostgreSQL과 동일할겁니다.

 

SQL>... 은 오라클

바로밑줄의 iSQL>은 SQL92로 이해하시면.. 되고요..

 

컬럼은 모두 integer형

샘플데이타는

SQL> select * from out1A;

.......C1.........C2

---------- ----------

.........1

.........2

....................1

....................2

SQL> select * from out1B

.......C1.........C2

---------- ----------

.........1

.........2

....................1

....................2

SQL> select * from out1C;

.......C1.........C2

---------- ----------

........11

이고..

 

변환예는 아래..

 

SQL> select a.*, b.* from out1A a, out1B b where a.c1(+) = b.c1;

iSQL> select a.*, b.* from out1B b left outer join out1A a on a.c1 = b.c1;

 

SQL> select a.*, b.* from out1A a, out1B b, out1C c where a.c1(+) = b.c1 and c.c1 = 11;

iSQL> select a.*, b.* from out1B b left outer join out1A a on a.c1 = b.c1, out1C c where c.c1 = 11;

 

SQL> select a.*, b.* from out1A a, out1B b where a.c1(+) = b.c1 AND a.c2(+) = b.c1;

iSQL> select a.*, b.* from out1B b left outer join out1A a on a.c1 = b.c1 AND a.c2 = b.c2;

 

SQL> select a.*, b.*, c.* from out1A a, out1B b, out1C c where a.c1(+) = b.c1 AND a.c2(+) = b.c1 and c.c1 = 11;

iSQL> select a.*, b.*, c.* from out1B b left outer join out1A a on A.C1 = B.C1 AND A.C2 = B.C2, out1C c where c.c1 = 11;

 

SQL> select a.*, b.*, c.* from out1A a, out1B b, out1C c where b.c1(+) = a.c1 and c.c1(+) = a.c1;

iSQL> select A.*, B.*, C.* from OUT1A A left outer join OUT1B B on B.C1 = A.C1 left outer join out1C c on c.c1 = a.c1

 

SQL> select a.*, b.* from out1A a, out1B b where a.c1(+) = 1;

iSQL> select a.*, b.* from out1B b left outer join out1A a on a.c1 = 1;

 

제가 Outer Join을 잘몰라서..

select a.*, b.* from out1A a, out1B b where a.c1(+) = 1;

이런 문장을 쓰나 고민했네요.

select a.*, b.* from out1A a, out1B b where a.c1 = 1;

와 결과가 같거든요..

 

그러나 outer join 조건이 하나 더 있으면 달라지네요.

 

SQL> select a.*, b.* from out1a a, out1b b where a.c1 = b.c1(+) and 1 = b.c1(+);

iSQL> select a.*, b.* from out1a a left outer join out1b b on b.c1 = a.c1 AND b.c1 = 1;

이 보통 의도한 경우고

SQL> select a.*, b.* from out1a a, out1b b where a.c1 = b.c1(+) and 1 = b.c1;

iSQL> select a.*, b.* from out1a a left outer join out1b b on b.c1 = a.c1 where b.c1 = 1;

이 잘못 사용된 경우 네요.

이 글에 대한 댓글이 총 1건 있습니다.

3개 테이블 간의 경우 ( 혹시 틀리면 지적 부탁합니다. )

 

select *

from out1a a, out1b b, out1c c

where b.c1(+) = a.c1

and c.c1(+) = a.c1

;

 

select *

from

out1a

left outer join

out1b

on out1a.c1 = out1b.c1

left outer join

out1c

on out1c.c1 = out1a.c1

;

 

create table out1a (c1 integer, c2 integer);

create table out1b (c1 integer, c2 integer);

create table out1c (c1 integer, c2 integer);

 

insert into out1a (c1) values (1);

insert into out1a (c1) values (2);

insert into out1a (c2) values (1);

insert into out1a (c2) values (2);

 

insert into out1b (c1) values (1);

insert into out1b (c1) values (2);

insert into out1b (c2) values (1);

insert into out1b (c2) values (2);

 

insert into out1c (c1) values (1);

insert into out1c (c2) values (1);

임옥섭(okseop7)님이 2005-06-07 17:43에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
4791postgresql 웹호스팅... [2]
대훈
2003-07-17
1427
4790PostgreSQL용 GUI 관리툴 [1]
김일형
2003-07-17
2753
4789PostgreSQL 과 Delphi6.0과 연결(ODBC나 BDE)..? ㅠ.ㅠ [3]
이호경
2003-07-16
2868
4788Outer Join 예입니다. [1]
노사모하나
2003-07-15
1814
4787완전초짜 질문.. [2]
초보
2003-07-14
1380
4785[질문] 크론작업은 정상적으로 돌았는데 dump가 되질 않습니다. [3]
박근준
2003-07-12
1161
4784질문]날자컬럼에 널값이나 아무값도 넣지 않는방법은? [5]
미달이
2003-07-10
1322
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다