<s>
A	O
join	O
clause	O
in	O
SQL	B-Language
–	O
corresponding	O
to	O
a	O
join	O
operation	O
in	O
relational	O
algebra	O
–	O
combines	O
columns	B-Application
from	O
one	O
or	O
more	O
tables	B-Application
into	O
a	O
new	O
table	O
.	O
</s>
<s>
Informally	O
,	O
a	O
join	O
stitches	O
two	O
tables	B-Application
and	O
puts	O
on	O
the	O
same	O
row	O
records	O
with	O
matching	O
fields	O
:	O
INNER	O
,	O
LEFT	O
OUTER	O
,	O
RIGHT	O
OUTER	O
,	O
FULL	O
OUTER	O
and	O
CROSS	O
.	O
</s>
<s>
To	O
explain	O
join	O
types	O
,	O
the	O
rest	O
of	O
this	O
article	O
uses	O
the	O
following	O
tables	B-Application
:	O
</s>
<s>
Department.DepartmentID	O
is	O
the	O
primary	B-Application
key	I-Application
of	O
the	O
Department	O
table	O
,	O
whereas	O
Employee.DepartmentID	O
is	O
a	O
foreign	B-Application
key	I-Application
.	O
</s>
<s>
This	O
is	O
the	O
SQL	B-Language
statement	O
to	O
create	O
the	O
above	O
tables	B-Application
:	O
</s>
<s>
CROSS	O
JOIN	O
returns	O
the	O
Cartesian	O
product	O
of	O
rows	O
from	O
tables	B-Application
in	O
the	O
join	O
.	O
</s>
<s>
CROSS	O
JOIN	O
does	O
not	O
itself	O
apply	O
any	O
predicate	B-Algorithm
to	O
filter	O
rows	O
from	O
the	O
joined	O
table	O
.	O
</s>
<s>
The	O
results	O
of	O
a	O
CROSS	O
JOIN	O
can	O
be	O
filtered	O
using	O
a	O
WHERE	B-Language
clause	I-Language
,	O
which	O
may	O
then	O
produce	O
the	O
equivalent	O
of	O
an	O
inner	O
join	O
.	O
</s>
<s>
In	O
the	O
SQL:2011	B-Language
standard	O
,	O
cross	O
joins	O
are	O
part	O
of	O
the	O
optional	O
F401	O
,	O
"	O
Extended	O
joined	O
table	O
"	O
,	O
package	O
.	O
</s>
<s>
An	O
inner	O
join	O
requires	O
each	O
row	O
in	O
the	O
two	O
joined	O
tables	B-Application
to	O
have	O
matching	O
column	O
values	O
,	O
and	O
is	O
a	O
commonly	O
used	O
join	O
operation	O
in	O
applications	B-Application
but	O
should	O
not	O
be	O
assumed	O
to	O
be	O
the	O
best	O
choice	O
in	O
all	O
situations	O
.	O
</s>
<s>
Inner	O
join	O
creates	O
a	O
new	O
result	O
table	O
by	O
combining	O
column	O
values	O
of	O
two	O
tables	B-Application
(	O
A	O
and	O
B	O
)	O
based	O
upon	O
the	O
join-predicate	O
.	O
</s>
<s>
The	O
query	B-Language
compares	O
each	O
row	O
of	O
A	O
with	O
each	O
row	O
of	O
B	O
to	O
find	O
all	O
pairs	O
of	O
rows	O
that	O
satisfy	O
the	O
join-predicate	O
.	O
</s>
<s>
When	O
the	O
join-predicate	O
is	O
satisfied	O
by	O
matching	O
non-NULL	O
values	O
,	O
column	O
values	O
for	O
each	O
matched	O
pair	O
of	O
rows	O
of	O
A	O
and	O
B	O
are	O
combined	O
into	O
a	O
result	O
row	O
.	O
</s>
<s>
The	O
result	O
of	O
the	O
join	O
can	O
be	O
defined	O
as	O
the	O
outcome	O
of	O
first	O
taking	O
the	O
Cartesian	O
product	O
(	O
or	O
Cross	O
join	O
)	O
of	O
all	O
rows	O
in	O
the	O
tables	B-Application
(	O
combining	O
every	O
row	O
in	O
table	O
A	O
with	O
every	O
row	O
in	O
table	O
B	O
)	O
and	O
then	O
returning	O
all	O
rows	O
that	O
satisfy	O
the	O
join	O
predicate	B-Algorithm
.	O
</s>
<s>
Actual	O
SQL	B-Language
implementations	O
normally	O
use	O
other	O
approaches	O
,	O
such	O
as	O
hash	B-Algorithm
joins	I-Algorithm
or	O
sort-merge	B-Algorithm
joins	I-Algorithm
,	O
since	O
computing	O
the	O
Cartesian	O
product	O
is	O
slower	O
and	O
would	O
often	O
require	O
a	O
prohibitively	O
large	O
amount	O
of	O
memory	O
to	O
store	O
.	O
</s>
<s>
SQL	B-Language
specifies	O
two	O
different	O
syntactical	O
ways	O
to	O
express	O
joins	O
:	O
the	O
"	O
explicit	O
join	O
notation	O
"	O
and	O
the	O
"	O
implicit	O
join	O
notation	O
"	O
.	O
</s>
<s>
The	O
"	O
explicit	O
join	O
notation	O
"	O
uses	O
the	O
JOIN	O
keyword	O
,	O
optionally	O
preceded	O
by	O
the	O
INNER	O
keyword	O
,	O
to	O
specify	O
the	O
table	O
to	O
join	O
,	O
and	O
the	O
ON	O
keyword	O
to	O
specify	O
the	O
predicates	B-Algorithm
for	O
the	O
join	O
,	O
as	O
in	O
the	O
following	O
example	O
:	O
</s>
<s>
The	O
"	O
implicit	O
join	O
notation	O
"	O
simply	O
lists	O
the	O
tables	B-Application
for	O
joining	O
,	O
in	O
the	O
FROM	O
clause	O
of	O
the	O
SELECT	O
statement	O
,	O
using	O
commas	O
to	O
separate	O
them	O
.	O
</s>
<s>
Thus	O
it	O
specifies	O
a	O
cross	O
join	O
,	O
and	O
the	O
WHERE	B-Language
clause	I-Language
may	O
apply	O
additional	O
filter-predicates	O
(	O
which	O
function	O
comparably	O
to	O
the	O
join-predicates	O
in	O
the	O
explicit	O
notation	O
)	O
.	O
</s>
<s>
The	O
queries	B-Language
given	O
in	O
the	O
examples	O
above	O
will	O
join	O
the	O
Employee	O
and	O
Department	O
tables	B-Application
using	O
the	O
DepartmentID	O
column	O
of	O
both	O
tables	B-Application
.	O
</s>
<s>
Where	O
the	O
DepartmentID	O
of	O
these	O
tables	B-Application
match	O
(	O
i.e.	O
</s>
<s>
the	O
join-predicate	O
is	O
satisfied	O
)	O
,	O
the	O
query	B-Language
will	O
combine	O
the	O
LastName	O
,	O
DepartmentID	O
and	O
DepartmentName	O
columns	B-Application
from	O
the	O
two	O
tables	B-Application
into	O
a	O
result	O
row	O
.	O
</s>
<s>
Thus	O
the	O
result	O
of	O
the	O
execution	B-Language
of	O
the	O
query	B-Language
above	O
will	O
be	O
:	O
</s>
<s>
The	O
employee	O
"	O
Williams	O
"	O
and	O
the	O
department	O
"	O
Marketing	O
"	O
do	O
not	O
appear	O
in	O
the	O
query	B-Language
execution	B-Language
results	O
.	O
</s>
<s>
Programmers	O
should	O
take	O
special	O
care	O
when	O
joining	O
tables	B-Application
on	O
columns	B-Application
that	O
can	O
contain	O
NULL	B-Language
values	O
,	O
since	O
NULL	B-Language
will	O
never	O
match	O
any	O
other	O
value	O
(	O
not	O
even	O
NULL	B-Language
itself	O
)	O
,	O
unless	O
the	O
join	O
condition	O
explicitly	O
uses	O
a	O
combination	O
predicate	B-Algorithm
that	O
first	O
checks	O
that	O
the	O
joins	O
columns	B-Application
are	O
NOT	O
NULL	B-Language
before	O
applying	O
the	O
remaining	O
predicate	B-Algorithm
condition(s )	O
.	O
</s>
<s>
The	O
Inner	O
Join	O
can	O
only	O
be	O
safely	O
used	O
in	O
a	O
database	O
that	O
enforces	O
referential	B-General_Concept
integrity	I-General_Concept
or	O
where	O
the	O
join	O
columns	B-Application
are	O
guaranteed	O
not	O
to	O
be	O
NULL	B-Language
.	O
</s>
<s>
Many	O
transaction	B-General_Concept
processing	I-General_Concept
relational	O
databases	O
rely	O
on	O
Atomicity	O
,	O
Consistency	O
,	O
Isolation	O
,	O
Durability	O
(	O
ACID	O
)	O
data	O
update	O
standards	O
to	O
ensure	O
data	O
integrity	O
,	O
making	O
inner	O
joins	O
an	O
appropriate	O
choice	O
.	O
</s>
<s>
However	O
,	O
transaction	O
databases	O
usually	O
also	O
have	O
desirable	O
join	O
columns	B-Application
that	O
are	O
allowed	O
to	O
be	O
NULL	B-Language
.	O
</s>
<s>
Many	O
reporting	O
relational	O
database	O
and	O
data	O
warehouses	O
use	O
high	O
volume	O
Extract	O
,	O
Transform	O
,	O
Load	O
(	O
ETL	O
)	O
batch	O
updates	O
which	O
make	O
referential	B-General_Concept
integrity	I-General_Concept
difficult	O
or	O
impossible	O
to	O
enforce	O
,	O
resulting	O
in	O
potentially	O
NULL	B-Language
join	O
columns	B-Application
that	O
an	O
SQL	B-Language
query	B-Language
author	O
cannot	O
modify	O
and	O
which	O
cause	O
inner	O
joins	O
to	O
omit	O
data	O
with	O
no	O
indication	O
of	O
an	O
error	O
.	O
</s>
<s>
A	O
left	O
outer	O
join	O
can	O
usually	O
be	O
substituted	O
for	O
an	O
inner	O
join	O
when	O
the	O
join	O
columns	B-Application
in	O
one	O
table	O
may	O
contain	O
NULL	B-Language
values	O
.	O
</s>
<s>
Any	O
data	O
column	O
that	O
may	O
be	O
NULL	B-Language
(	O
empty	O
)	O
should	O
never	O
be	O
used	O
as	O
a	O
link	O
in	O
an	O
inner	O
join	O
,	O
unless	O
the	O
intended	O
result	O
is	O
to	O
eliminate	O
the	O
rows	O
with	O
the	O
NULL	B-Language
value	O
.	O
</s>
<s>
If	O
NULL	B-Language
join	O
columns	B-Application
are	O
to	O
be	O
deliberately	O
removed	O
from	O
the	O
result	B-Application
set	I-Application
,	O
an	O
inner	O
join	O
can	O
be	O
faster	O
than	O
an	O
outer	O
join	O
because	O
the	O
table	B-Language
join	I-Language
and	O
filtering	O
is	O
done	O
in	O
a	O
single	O
step	O
.	O
</s>
<s>
Conversely	O
,	O
an	O
inner	O
join	O
can	O
result	O
in	O
disastrously	O
slow	O
performance	O
or	O
even	O
a	O
server	O
crash	O
when	O
used	O
in	O
a	O
large	O
volume	O
query	B-Language
in	O
combination	O
with	O
database	O
functions	O
in	O
an	O
SQL	B-Language
Where	I-Language
clause	O
.	O
</s>
<s>
A	O
function	O
in	O
an	O
SQL	B-Language
Where	I-Language
clause	O
can	O
result	O
in	O
the	O
database	O
ignoring	O
relatively	O
compact	O
table	B-Data_Structure
indexes	I-Data_Structure
.	O
</s>
<s>
The	O
database	O
may	O
read	O
and	O
inner	O
join	O
the	O
selected	O
columns	B-Application
from	O
both	O
tables	B-Application
before	O
reducing	O
the	O
number	O
of	O
rows	O
using	O
the	O
filter	O
that	O
depends	O
on	O
a	O
calculated	O
value	O
,	O
resulting	O
in	O
a	O
relatively	O
enormous	O
amount	O
of	O
inefficient	O
processing	O
.	O
</s>
<s>
When	O
a	O
result	B-Application
set	I-Application
is	O
produced	O
by	O
joining	O
several	O
tables	B-Application
,	O
including	O
master	O
tables	B-Application
used	O
to	O
look	O
up	O
full-text	O
descriptions	O
of	O
numeric	O
identifier	O
codes	O
(	O
a	O
Lookup	B-Data_Structure
table	I-Data_Structure
)	O
,	O
a	O
NULL	B-Language
value	O
in	O
any	O
one	O
of	O
the	O
foreign	B-Application
keys	I-Application
can	O
result	O
in	O
the	O
entire	O
row	O
being	O
eliminated	O
from	O
the	O
result	B-Application
set	I-Application
,	O
with	O
no	O
indication	O
of	O
error	O
.	O
</s>
<s>
A	O
complex	O
SQL	B-Language
query	B-Language
that	O
includes	O
one	O
or	O
more	O
inner	O
joins	O
and	O
several	O
outer	O
joins	O
has	O
the	O
same	O
risk	O
for	O
NULL	B-Language
values	O
in	O
the	O
inner	O
join	O
link	O
columns	B-Application
.	O
</s>
<s>
A	O
commitment	O
to	O
SQL	B-Language
code	O
containing	O
inner	O
joins	O
assumes	O
NULL	B-Language
join	O
columns	B-Application
will	O
not	O
be	O
introduced	O
by	O
future	O
changes	O
,	O
including	O
vendor	O
updates	O
,	O
design	O
changes	O
and	O
bulk	O
processing	O
outside	O
of	O
the	O
application	O
's	O
data	O
validation	O
rules	O
such	O
as	O
data	O
conversions	O
,	O
migrations	O
,	O
bulk	O
imports	O
and	O
merges	O
.	O
</s>
<s>
An	O
equi-join	O
is	O
a	O
specific	O
type	O
of	O
comparator-based	O
join	O
,	O
that	O
uses	O
only	O
equality	O
comparisons	O
in	O
the	O
join-predicate	O
.	O
</s>
<s>
The	O
query	B-Language
shown	O
above	O
has	O
already	O
provided	O
an	O
example	O
of	O
an	O
equi-join	O
:	O
</s>
<s>
If	O
columns	B-Application
in	O
an	O
equi-join	O
have	O
the	O
same	O
name	O
,	O
SQL-92	B-Language
provides	O
an	O
optional	O
shorthand	O
notation	O
for	O
expressing	O
equi-joins	O
,	O
by	O
way	O
of	O
the	O
USING	O
construct	O
:	O
</s>
<s>
The	O
USING	O
construct	O
is	O
more	O
than	O
mere	O
syntactic	O
sugar	O
,	O
however	O
,	O
since	O
the	O
result	B-Application
set	I-Application
differs	O
from	O
the	O
result	B-Application
set	I-Application
of	O
the	O
version	O
with	O
the	O
explicit	O
predicate	B-Algorithm
.	O
</s>
<s>
Specifically	O
,	O
any	O
columns	B-Application
mentioned	O
in	O
the	O
USING	O
list	O
will	O
appear	O
only	O
once	O
,	O
with	O
an	O
unqualified	O
name	O
,	O
rather	O
than	O
once	O
for	O
each	O
table	O
in	O
the	O
join	O
.	O
</s>
<s>
The	O
USING	O
clause	O
is	O
not	O
supported	O
by	O
MS	B-Application
SQL	I-Application
Server	I-Application
and	O
Sybase	B-Application
.	O
</s>
<s>
Natural	O
join	O
( ⋈	O
)	O
is	O
a	O
binary	O
operator	O
that	O
is	O
written	O
as	O
(	O
R	O
⋈	O
S	O
)	O
where	O
R	O
and	O
S	O
are	O
relations	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
the	O
natural	O
join	O
is	O
the	O
set	O
of	O
all	O
combinations	O
of	O
tuples	B-Application
in	O
R	O
and	O
S	O
that	O
are	O
equal	O
on	O
their	O
common	O
attribute	O
names	O
.	O
</s>
<s>
For	O
an	O
example	O
consider	O
the	O
tables	B-Application
Employee	O
and	O
Dept	O
and	O
their	O
natural	O
join	O
:	O
</s>
<s>
This	O
can	O
also	O
be	O
used	O
to	O
define	O
composition	O
of	O
relations	B-Language
.	O
</s>
<s>
Note	O
that	O
if	O
the	O
same	O
variable	O
appears	O
in	O
each	O
of	O
two	O
predicates	B-Algorithm
that	O
are	O
connected	O
by	O
AND	O
,	O
then	O
that	O
variable	O
stands	O
for	O
the	O
same	O
thing	O
and	O
both	O
appearances	O
must	O
always	O
be	O
substituted	O
by	O
the	O
same	O
value	O
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
natural	O
join	O
allows	O
the	O
combination	O
of	O
relations	B-Language
that	O
are	O
associated	O
by	O
a	O
foreign	B-Application
key	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
above	O
example	O
a	O
foreign	B-Application
key	I-Application
probably	O
holds	O
from	O
Employee.DeptName	O
to	O
Dept.DeptName	O
and	O
then	O
the	O
natural	O
join	O
of	O
Employee	O
and	O
Dept	O
combines	O
all	O
employees	O
with	O
their	O
departments	O
.	O
</s>
<s>
This	O
works	O
because	O
the	O
foreign	B-Application
key	I-Application
holds	O
between	O
attributes	O
with	O
the	O
same	O
name	O
.	O
</s>
<s>
If	O
this	O
is	O
not	O
the	O
case	O
such	O
as	O
in	O
the	O
foreign	B-Application
key	I-Application
from	O
Dept.manager	O
to	O
Employee.Name	O
then	O
these	O
columns	B-Application
have	O
to	O
be	O
renamed	O
before	O
the	O
natural	O
join	O
is	O
taken	O
.	O
</s>
<s>
where	O
Fun	O
is	O
a	O
predicate	B-Algorithm
that	O
is	O
true	O
for	O
a	O
relation	B-Algorithm
r	O
if	O
and	O
only	O
if	O
r	O
is	O
a	O
function	O
.	O
</s>
<s>
Then	O
we	O
take	O
the	O
Cartesian	O
product	O
and	O
select	O
the	O
tuples	B-Application
that	O
are	O
to	O
be	O
joined	O
:	O
</s>
<s>
A	O
natural	O
join	O
is	O
a	O
type	O
of	O
equi-join	O
where	O
the	O
join	O
predicate	B-Algorithm
arises	O
implicitly	O
by	O
comparing	O
all	O
columns	B-Application
in	O
both	O
tables	B-Application
that	O
have	O
the	O
same	O
column-names	O
in	O
the	O
joined	O
tables	B-Application
.	O
</s>
<s>
The	O
resulting	O
joined	O
table	O
contains	O
only	O
one	O
column	O
for	O
each	O
pair	O
of	O
equally	O
named	O
columns	B-Application
.	O
</s>
<s>
In	O
the	O
case	O
that	O
no	O
columns	B-Application
with	O
the	O
same	O
names	O
are	O
found	O
,	O
the	O
result	O
is	O
a	O
cross	O
join	O
.	O
</s>
<s>
An	O
existing	O
natural	O
join	O
might	O
then	O
"	O
naturally	O
"	O
use	O
the	O
new	O
column	O
for	O
comparisons	O
,	O
making	O
comparisons/matches	O
using	O
different	O
criteria	O
(	O
from	O
different	O
columns	B-Application
)	O
than	O
before	O
.	O
</s>
<s>
Thus	O
an	O
existing	O
query	B-Language
could	O
produce	O
different	O
results	O
,	O
even	O
though	O
the	O
data	O
in	O
the	O
tables	B-Application
have	O
not	O
been	O
changed	O
,	O
but	O
only	O
augmented	O
.	O
</s>
<s>
The	O
use	O
of	O
column	O
names	O
to	O
automatically	O
determine	O
table	O
links	O
is	O
not	O
an	O
option	O
in	O
large	O
databases	O
with	O
hundreds	O
or	O
thousands	O
of	O
tables	B-Application
where	O
it	O
would	O
place	O
an	O
unrealistic	O
constraint	O
on	O
naming	O
conventions	O
.	O
</s>
<s>
Real	O
world	O
databases	O
are	O
commonly	O
designed	O
with	O
foreign	B-Application
key	I-Application
data	O
that	O
is	O
not	O
consistently	O
populated	O
(	O
NULL	B-Language
values	O
are	O
allowed	O
)	O
,	O
due	O
to	O
business	O
rules	O
and	O
context	O
.	O
</s>
<s>
It	O
is	O
common	O
practice	O
to	O
modify	O
column	O
names	O
of	O
similar	O
data	O
in	O
different	O
tables	B-Application
and	O
this	O
lack	O
of	O
rigid	O
consistency	O
relegates	O
natural	O
joins	O
to	O
a	O
theoretical	O
concept	O
for	O
discussion	O
.	O
</s>
<s>
The	O
above	O
sample	O
query	B-Language
for	O
inner	O
joins	O
can	O
be	O
expressed	O
as	O
a	O
natural	O
join	O
in	O
the	O
following	O
way	O
:	O
</s>
<s>
PostgreSQL	O
,	O
MySQL	B-Application
and	O
Oracle	B-Application
support	O
natural	O
joins	O
;	O
Microsoft	O
T-SQL	O
and	O
IBM	O
DB2	O
do	O
not	O
.	O
</s>
<s>
The	O
columns	B-Application
used	O
in	O
the	O
join	O
are	O
implicit	O
so	O
the	O
join	O
code	O
does	O
not	O
show	O
which	O
columns	B-Application
are	O
expected	O
,	O
and	O
a	O
change	O
in	O
column	O
names	O
may	O
change	O
the	O
results	O
.	O
</s>
<s>
In	O
the	O
SQL:2011	B-Language
standard	O
,	O
natural	O
joins	O
are	O
part	O
of	O
the	O
optional	O
F401	O
,	O
"	O
Extended	O
joined	O
table	O
"	O
,	O
package	O
.	O
</s>
<s>
In	O
many	O
database	O
environments	O
the	O
column	O
names	O
are	O
controlled	O
by	O
an	O
outside	O
vendor	O
,	O
not	O
the	O
query	B-Language
developer	O
.	O
</s>
<s>
Like	O
inner	O
joins	O
,	O
one	O
can	O
further	O
sub-categorize	O
all	O
types	O
of	O
outer	O
joins	O
as	O
equi-joins	O
,	O
natural	O
joins	O
,	O
ON	O
<predicate>	O
(θ-	O
join	O
)	O
,	O
etc	O
.	O
</s>
<s>
No	O
implicit	O
join-notation	O
for	O
outer	O
joins	O
exists	O
in	O
standard	O
SQL	B-Language
.	O
</s>
<s>
The	O
result	O
of	O
a	O
left	O
outer	O
join	O
(	O
or	O
simply	O
left	O
join	O
)	O
for	O
tables	B-Application
A	O
and	O
B	O
always	O
contains	O
all	O
rows	O
of	O
the	O
"	O
left	O
"	O
table	O
(	O
A	O
)	O
,	O
even	O
if	O
the	O
join-condition	O
does	O
not	O
find	O
any	O
matching	O
row	O
in	O
the	O
"	O
right	O
"	O
table	O
(	O
B	O
)	O
.	O
</s>
<s>
This	O
means	O
that	O
if	O
the	O
ON	O
clause	O
matches	O
0	O
(	O
zero	O
)	O
rows	O
in	O
B	O
(	O
for	O
a	O
given	O
row	O
in	O
A	O
)	O
,	O
the	O
join	O
will	O
still	O
return	O
a	O
row	O
in	O
the	O
result	O
(	O
for	O
that	O
row	O
)	O
—	O
but	O
with	O
NULL	B-Language
in	O
each	O
column	O
from	O
B	O
.	O
</s>
<s>
A	O
left	O
outer	O
join	O
returns	O
all	O
the	O
values	O
from	O
an	O
inner	O
join	O
plus	O
all	O
values	O
in	O
the	O
left	O
table	O
that	O
do	O
not	O
match	O
to	O
the	O
right	O
table	O
,	O
including	O
rows	O
with	O
NULL	B-Language
(	O
empty	O
)	O
values	O
in	O
the	O
link	O
column	O
.	O
</s>
<s>
Oracle	B-Application
supports	O
the	O
deprecated	O
syntax	O
:	O
</s>
<s>
Sybase	B-Application
supports	O
the	O
syntax	O
(	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
deprecated	O
this	O
syntax	O
since	O
version	O
2000	O
)	O
:	O
</s>
<s>
IBM	B-Application
Informix	I-Application
supports	O
the	O
syntax	O
:	O
</s>
<s>
A	O
right	O
outer	O
join	O
(	O
or	O
right	O
join	O
)	O
closely	O
resembles	O
a	O
left	O
outer	O
join	O
,	O
except	O
with	O
the	O
treatment	O
of	O
the	O
tables	B-Application
reversed	O
.	O
</s>
<s>
If	O
no	O
matching	O
row	O
from	O
the	O
"	O
left	O
"	O
table	O
(	O
A	O
)	O
exists	O
,	O
NULL	B-Language
will	O
appear	O
in	O
columns	B-Application
from	O
A	O
for	O
those	O
rows	O
that	O
have	O
no	O
match	O
in	O
B	O
.	O
</s>
<s>
A	O
right	O
outer	O
join	O
returns	O
all	O
the	O
values	O
from	O
the	O
right	O
table	O
and	O
matched	O
values	O
from	O
the	O
left	O
table	O
(	O
NULL	B-Language
in	O
the	O
case	O
of	O
no	O
matching	O
join	O
predicate	B-Algorithm
)	O
.	O
</s>
<s>
Where	O
rows	O
in	O
the	O
FULL	O
OUTER	O
JOINed	O
tables	B-Application
do	O
not	O
match	O
,	O
the	O
result	B-Application
set	I-Application
will	O
have	O
NULL	B-Language
values	O
for	O
every	O
column	O
of	O
the	O
table	O
that	O
lacks	O
a	O
matching	O
row	O
.	O
</s>
<s>
For	O
those	O
rows	O
that	O
do	O
match	O
,	O
a	O
single	O
row	O
will	O
be	O
produced	O
in	O
the	O
result	B-Application
set	I-Application
(	O
containing	O
columns	B-Application
populated	O
from	O
both	O
tables	B-Application
)	O
.	O
</s>
<s>
Some	O
database	O
systems	O
do	O
not	O
support	O
the	O
full	O
outer	O
join	O
functionality	O
directly	O
,	O
but	O
they	O
can	O
emulate	O
it	O
through	O
the	O
use	O
of	O
an	O
inner	O
join	O
and	O
UNION	O
ALL	O
selects	O
of	O
the	O
"	O
single	O
table	B-Application
rows	I-Application
"	O
from	O
left	O
and	O
right	O
tables	B-Application
respectively	O
.	O
</s>
<s>
If	O
there	O
were	O
two	O
separate	O
tables	B-Application
for	O
employees	O
and	O
a	O
query	B-Language
which	O
requested	O
employees	O
in	O
the	O
first	O
table	O
having	O
the	O
same	O
country	O
as	O
employees	O
in	O
the	O
second	O
table	O
,	O
a	O
normal	O
join	O
operation	O
could	O
be	O
used	O
to	O
find	O
the	O
answer	O
table	O
.	O
</s>
<s>
An	O
example	O
solution	O
query	B-Language
could	O
be	O
as	O
follows	O
:	O
</s>
<s>
F	O
and	O
S	O
are	O
aliases	B-Language
for	O
the	O
first	O
and	O
second	O
copies	O
of	O
the	O
employee	O
table	O
.	O
</s>
<s>
Much	O
work	O
in	O
database-systems	O
has	O
aimed	O
at	O
efficient	O
implementation	O
of	O
joins	O
,	O
because	O
relational	O
systems	O
commonly	O
call	O
for	O
joins	O
,	O
yet	O
face	O
difficulties	O
in	O
optimising	O
their	O
efficient	O
execution	B-Language
.	O
</s>
<s>
In	O
practice	O
,	O
this	O
means	O
that	O
the	O
user	O
merely	O
supplies	O
the	O
list	O
of	O
tables	B-Application
for	O
joining	O
and	O
the	O
join	O
conditions	O
to	O
use	O
,	O
and	O
the	O
database	O
system	O
has	O
the	O
task	O
of	O
determining	O
the	O
most	O
efficient	O
way	O
to	O
perform	O
the	O
operation	O
.	O
</s>
<s>
A	O
query	B-Language
optimizer	I-Language
determines	O
how	O
to	O
execute	O
a	O
query	B-Language
containing	O
joins	O
.	O
</s>
<s>
A	O
query	B-Language
optimizer	I-Language
has	O
two	O
basic	O
freedoms	O
:	O
</s>
<s>
Join	O
order	O
:	O
Because	O
it	O
joins	O
functions	O
commutatively	O
and	O
associatively	O
,	O
the	O
order	O
in	O
which	O
the	O
system	O
joins	O
tables	B-Application
does	O
not	O
change	O
the	O
final	O
result	B-Application
set	I-Application
of	O
the	O
query	B-Language
.	O
</s>
<s>
Join	O
method	O
:	O
Given	O
two	O
tables	B-Application
and	O
a	O
join	O
condition	O
,	O
multiple	O
algorithms	O
can	O
produce	O
the	O
result	B-Application
set	I-Application
of	O
the	O
join	O
.	O
</s>
<s>
Which	O
algorithm	O
runs	O
most	O
efficiently	O
depends	O
on	O
the	O
sizes	O
of	O
the	O
input	O
tables	B-Application
,	O
the	O
number	O
of	O
rows	O
from	O
each	O
table	O
that	O
match	O
the	O
join	O
condition	O
,	O
and	O
the	O
operations	O
required	O
by	O
the	O
rest	O
of	O
the	O
query	B-Language
.	O
</s>
<s>
In	O
the	O
case	O
of	O
nested	O
loops	O
,	O
for	O
example	O
,	O
the	O
database	O
system	O
will	O
scan	O
the	O
entire	O
inner	O
relation	B-Algorithm
for	O
each	O
row	O
of	O
the	O
outer	O
relation	B-Algorithm
.	O
</s>
<s>
One	O
can	O
classify	O
query-plans	O
involving	O
joins	O
as	O
follows	O
:	O
</s>
<s>
These	O
names	O
derive	O
from	O
the	O
appearance	O
of	O
the	O
query	B-Language
plan	I-Language
if	O
drawn	O
as	O
a	O
tree	B-Application
,	O
with	O
the	O
outer	O
join	O
relation	B-Algorithm
on	O
the	O
left	O
and	O
the	O
inner	O
relation	B-Algorithm
on	O
the	O
right	O
(	O
as	O
convention	O
dictates	O
)	O
.	O
</s>
<s>
Three	O
fundamental	O
algorithms	O
for	O
performing	O
a	O
binary	O
join	O
operation	O
exist	O
:	O
nested	B-Algorithm
loop	I-Algorithm
join	I-Algorithm
,	O
sort-merge	B-Algorithm
join	I-Algorithm
and	O
hash	B-Algorithm
join	I-Algorithm
.	O
</s>
<s>
Worst-case	B-General_Concept
optimal	O
join	O
algorithms	O
are	O
asymptotically	O
faster	O
than	O
binary	O
join	O
algorithms	O
for	O
joins	O
between	O
more	O
than	O
two	O
relations	B-Language
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
Join	O
indexes	O
are	O
database	B-Data_Structure
indexes	I-Data_Structure
that	O
facilitate	O
the	O
processing	O
of	O
join	O
queries	B-Language
in	O
data	O
warehouses	O
:	O
they	O
are	O
currently	O
(	O
2012	O
)	O
available	O
in	O
implementations	O
by	O
Oracle	B-Application
and	O
Teradata	O
.	O
</s>
<s>
In	O
the	O
Teradata	O
implementation	O
,	O
specified	O
columns	B-Application
,	O
aggregate	O
functions	O
on	O
columns	B-Application
,	O
or	O
components	O
of	O
date	O
columns	B-Application
from	O
one	O
or	O
more	O
tables	B-Application
are	O
specified	O
using	O
a	O
syntax	O
similar	O
to	O
the	O
definition	O
of	O
a	O
database	B-Language
view	I-Language
:	O
up	O
to	O
64	O
columns/column	O
expressions	O
can	O
be	O
specified	O
in	O
a	O
single	O
join	O
index	O
.	O
</s>
<s>
Optionally	O
,	O
a	O
column	O
that	O
defines	O
the	O
primary	B-Application
key	I-Application
of	O
the	O
composite	O
data	O
may	O
also	O
be	O
specified	O
:	O
on	O
parallel	O
hardware	O
,	O
the	O
column	O
values	O
are	O
used	O
to	O
partition	O
the	O
index	O
's	O
contents	O
across	O
multiple	O
disks	O
.	O
</s>
<s>
When	O
the	O
source	O
tables	B-Application
are	O
updated	O
interactively	O
by	O
users	O
,	O
the	O
contents	O
of	O
the	O
join	O
index	O
are	O
automatically	O
updated	O
.	O
</s>
<s>
Any	O
query	B-Language
whose	O
WHERE	B-Language
clause	I-Language
specifies	O
any	O
combination	O
of	O
columns	B-Application
or	O
column	O
expressions	O
that	O
are	O
an	O
exact	O
subset	O
of	O
those	O
defined	O
in	O
a	O
join	O
index	O
(	O
a	O
so-called	O
"	O
covering	O
query	B-Language
"	O
)	O
will	O
cause	O
the	O
join	O
index	O
,	O
rather	O
than	O
the	O
original	O
tables	B-Application
and	O
their	O
indexes	O
,	O
to	O
be	O
consulted	O
during	O
query	B-Language
execution	B-Language
.	O
</s>
<s>
The	O
Oracle	B-Application
implementation	O
limits	O
itself	O
to	O
using	O
bitmap	B-Data_Structure
indexes	I-Data_Structure
.	O
</s>
<s>
A	O
bitmap	O
join	O
index	O
is	O
used	O
for	O
low-cardinality	O
columns	B-Application
(	O
i.e.	O
,	O
columns	B-Application
containing	O
fewer	O
than	O
300	O
distinct	O
values	O
,	O
according	O
to	O
the	O
Oracle	B-Application
documentation	O
)	O
:	O
it	O
combines	O
low-cardinality	O
columns	B-Application
from	O
multiple	O
related	O
tables	B-Application
.	O
</s>
<s>
The	O
example	O
Oracle	B-Application
uses	O
is	O
that	O
of	O
an	O
inventory	O
system	O
,	O
where	O
different	O
suppliers	O
provide	O
different	O
parts	O
.	O
</s>
<s>
The	O
schema	B-Application
has	O
three	O
linked	O
tables	B-Application
:	O
two	O
"	O
master	O
tables	B-Application
"	O
,	O
Part	O
and	O
Supplier	O
,	O
and	O
a	O
"	O
detail	O
table	O
"	O
,	O
Inventory	O
.	O
</s>
<s>
The	O
bitmap	O
join	O
index	O
is	O
defined	O
using	O
a	O
standard	O
three-table	O
join	O
on	O
the	O
three	O
tables	B-Application
above	O
,	O
and	O
specifying	O
the	O
Part_Type	O
and	O
Supplier_State	O
columns	B-Application
for	O
the	O
index	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
defined	O
on	O
the	O
Inventory	O
table	O
,	O
even	O
though	O
the	O
columns	B-Application
Part_Type	O
and	O
Supplier_State	O
are	O
"	O
borrowed	O
"	O
from	O
Supplier	O
and	O
Part	O
respectively	O
.	O
</s>
<s>
As	O
for	O
Teradata	O
,	O
an	O
Oracle	B-Application
bitmap	O
join	O
index	O
is	O
only	O
utilized	O
to	O
answer	O
a	O
query	B-Language
when	O
the	O
query	B-Language
's	O
WHERE	B-Language
clause	I-Language
specifies	O
columns	B-Application
limited	O
to	O
those	O
that	O
are	O
included	O
in	O
the	O
join	O
index	O
.	O
</s>
<s>
Some	O
database	O
systems	O
allow	O
the	O
user	O
to	O
force	O
the	O
system	O
to	O
read	O
the	O
tables	B-Application
in	O
a	O
join	O
in	O
a	O
particular	O
order	O
.	O
</s>
<s>
This	O
is	O
used	O
when	O
the	O
join	O
optimizer	O
chooses	O
to	O
read	O
the	O
tables	B-Application
in	O
an	O
inefficient	O
order	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
MySQL	B-Application
the	O
command	O
STRAIGHT_JOIN	O
reads	O
the	O
tables	B-Application
in	O
exactly	O
the	O
order	O
listed	O
in	O
the	O
query	B-Language
.	O
</s>
