Página 1 de 1

FULL OUTER JOIN

Enviado: Seg, 11 Out 2004 2:48 pm
por LC_JK
Estou fazendo uma select com 2 tabelas.... as vezes em 1 tabela tem a informação e a 2 não.... e as vezes 2 tem e a 1 não....... tentei utilizar o FULL OUTER JOIN mas não está dando certo.... talvez eu não esteja fazendo da maneira correta. alguém sabe como posso fazer isso usando o FULL OUTER JOIN?!

Enviado: Seg, 11 Out 2004 4:12 pm
por dr_gori
Se você está usando o Oracle 8i ou anterior, você deve usar um UNION pra emular um full-outer-join...

Veja abaixo - Oracle 8i ou anterior:

Selecionar tudo

SQL> select p.part_id, s.supplier_name
  2  from part p, supplier s
  3  where p.supplier_id = s.supplier_id (+)
  4  union
  5  select p.part_id, s.supplier_name
  6  from part p, supplier s
  7  where p.supplier_id (+) = s.supplier_id;

PART SUPPLIER_NAME
---- --------------------
P1   Supplier#1
P2   Supplier#2
P3
P4
     Supplier#3
Também pode usar a nova feature do Oracle 9i:

Selecionar tudo

SQL> select p.part_id, s.supplier_name
  2  from part p full outer join supplier s
  3  on p.supplier_id = s.supplier_id;

PART SUPPLIER_NAME
---- --------------------
P1   Supplier#1
P2   Supplier#2
P4
P3
     Supplier#3
Esse exemplo eu tirei do oreillynet:
http://www.oreillynet.com/pub/a/network ... ljoin.html

Espero ter ajudado!

Enviado: Seg, 11 Out 2004 4:56 pm
por LC_JK
já fiz isso..... estou fazendo igual ao modelo q me passou..... mas esta dando o seguinte erro:
16:59:17 ORA-00933: SQL command not properly ended
o q esta de errado?!

Enviado: Seg, 11 Out 2004 5:03 pm
por tfg
Manda o SQL pra gente ver!! :-o

Enviado: Seg, 11 Out 2004 5:25 pm
por LC_JK
ai vai o código....

Selecionar tudo

select a.organization_id,
       a.inventory_item_id,
       a.subinventory_code,
       a.locator_id,
       b.organization_id,
       b.inventory_item_id,
       b.subinventory_code,
       b.locator_id
from nv_una_moviment a FULL OUTER JOIN inv_una_contagens b
   on a.organization_id   = b.organization_id
  and a.inventory_item_id = b.inventory_item_id
  and a.subinventory_code = b.subinventory 
  and a.locator_id        = b.locator_id 
  and a.lot_number        = b.lot_number;

Enviado: Qua, 13 Out 2004 11:24 am
por dr_gori
Que estranho... fiz um teste semelhante aqui com o Oracle 9.0.1.4.0 e funcionou perfeitamente.

Qual é a versão do seu oracle aí?

Tenta entrar no SCOTT e rodar esse sql abaixo...

Selecionar tudo

SQL> SELECT A.ENAME, A.DEPTNO, B.DEPTNO
  2  FROM EMP A FULL OUTER JOIN DEPT B
  3    ON A.DEPTNO=B.DEPTNO
  4  /

ENAME         DEPTNO    DEPTNO
---------- --------- ---------
SMITH             20        20
ALLEN             30        30
WARD              30        30
JONES             20        20
MARTIN            30        30
BLAKE             30        30
CLARK             10        10
SCOTT             20        20
KING              10        10
TURNER            30        30
ADAMS             20        20
JAMES             30        30
FORD              20        20
MILLER            10        10
                            40

15 rows selected.

SQL> 

Enviado: Qui, 13 Mar 2008 8:11 am
por jobson
dr_gori,

Essa dica foi muito boa, eliminei diversos union em minhas consultas. Dessa forma o código fica muito mais limpo e fácil manutenção.

Muito obrigado.

Dr. Gori (full outer join)

Enviado: Qua, 07 Mai 2008 4:23 pm
por mauli
Olha só, construi com full outer join e tudo certo (para duas tabelas), porem tenho algumas querys que preciso em um único sql utilizar o full outer join, pore para 4 tabelas.

Podes me ajudar?
Mauli