Some understanding about joins

14 visualizações
Pular para a primeira mensagem não lida

tawright915

não lida,
21 de set. de 2006, 16:52:1721/09/2006
para ORACLE_DBA_EXPERTS
Can someone please help me in understanding inner and outer joins? I
seem to have a block when it comes to understanding this concept.

And please if you have nothing helpful to contribute then please do not
reply.

Thanks
Tom

Charles Hooper

não lida,
21 de set. de 2006, 21:57:5421/09/2006
para ORACLE_DBA_EXPERTS

Short answer:
* Inner join - the value must be in BOTH tables
* Outer join - the value must be in at least ONE table

Assume that the following table and columns in those tables, and data
in those columns exist:
TABLE_1.ANIMAL
COW
PIG
ZEBRA
SHARK
ROOSTER
LION

TABLE_2.ANIMAL
COW
PIG
DOG

TABLE_3.ANIMAL
ZEBRA
LION
TIGER

Inner join TABLE_2 and TABLE_3
SELECT
T2.ANIMAL,
T3.ANIMAL
FROM
TABLE_2 T2,
TABLE_3 T3
WHERE
T2.ANIMAL=T3.ANIMAL;

(no results)
-------------------

(Left) Outer join TABLE_2 and TABLE_3, include all rows from TABLE_2
SELECT
T2.ANIMAL,
T3.ANIMAL
FROM
TABLE_2 T2,
TABLE_3 T3
WHERE
T2.ANIMAL=T3.ANIMAL(+);

T2.ANIMAL T3.ANIMAL
COW (null)
PIG (null)
DOG (null)
-------------------

Inner join TABLE_1 and TABLE_2
SELECT
T1.ANIMAL,
T2.ANIMAL
FROM
TABLE_1 T1,
TABLE_2 T2
WHERE
T1.ANIMAL=T2.ANIMAL;

TABLE_1.ANIMAL TABLE_2.ANIMAL
COW COW
PIG PIG
-------------------

(Right) Outer join TABLE_1 and TABLE_2, include all rows from TABLE_2
SELECT
T1.ANIMAL,
T2.ANIMAL
FROM
TABLE_1 T1,
TABLE_2 T2
WHERE
T1.ANIMAL(+)=T2.ANIMAL;

TABLE_1.ANIMAL TABLE_2.ANIMAL
COW COW
PIG PIG
(null) DOG
-------------------

(One Method, Full) Outer join TABLE_1 and TABLE_2, include all rows
SELECT
T1.ANIMAL,
T2.ANIMAL
FROM
TABLE_1 T1,
TABLE_2 T2
WHERE
T1.ANIMAL(+)=T2.ANIMAL
UNION
SELECT
T1.ANIMAL,
T2.ANIMAL
FROM
TABLE_1 T1,
TABLE_2 T2
WHERE
T1.ANIMAL=T2.ANIMAL(+);

TABLE_1.ANIMAL TABLE_2.ANIMAL
COW COW
PIG PIG
(null) DOG
ZEBRA (null)
SHARK (null)
ROOSTER (null)
LION (null)

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.

tawright915

não lida,
22 de set. de 2006, 09:38:0122/09/2006
para ORACLE_DBA_EXPERTS
Thank you so much. The light went on.

juan....@gmail.com

não lida,
27 de set. de 2006, 00:31:3527/09/2006
para ORACLE_DBA_EXPERTS
There's a good discussion at http://en.wikipedia.org/wiki/Join_(SQL)

ExpertDba

não lida,
27 de set. de 2006, 22:58:3527/09/2006
para ORACLE_DBA_EXPERTS
Charles Hooper,

Beautifully put answer!

regards,
Channesh

siva

não lida,
30 de set. de 2006, 00:18:0830/09/2006
para ORACLE_DBA_EXPERTS
Thanks Charles Hooper,

its really a nice reply it helped me to get out of the confusion
between the both

thanking you once again

regards

siva.

Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem