2. • A SQL JOIN clause combines records from two or more tables in
a Database.
• Means for combining fields from 2 tables by using values
common to each.
• Mainly 4 types
* INNER
* OUTER
* LEFT
*RIGHT
JION
4. Inner Join
• Creates a new result table by combining column values of two
tables based upon the join-predicate.
• 2 ways to express join :
* Explicit Join Notation
* Implicit Join Notation
6. The result of the execution of either of the two queries above will be:
7. Natural Join
• The join predicate arises implicitly by comparing all columns
in both tables that have the same column-names in the joined
tables.
• The resulting joined table contains only one column for each
pair of equally named columns.
8. The above sample query for inner joins can be expressed as a natural join
in the following way:
9. Outer Join
• An outer join does not require each record in the two joined
tables to have a matching record.
• The joined table retains each record, even if no other matching
record exists.
• Outer joins subdivide further into left outer joins, right outer
joins, and full outer joins, depending on which table's rows
are retained.
10. Left outer joins
• The result of a left outer join (or simply left join) for table A
and B always contains all records of the "left" table (A), even
if the join-condition does not find any matching record in the
"right" table (B).
• This means that if the ON clause matches 0 (zero) records in B
(for a given record in A), the join will still return a row in the
result (for that record)—but with NULL in each column from
B.
13. Semi Join [(⋉) or (⋊) ]
• The left semi join is joining similar to the natural join and
written as R ⋉ S where R and S are relations.
• The result of this semi join is the set of all tuples in R for
which there is a tuple in S that is equal on their common
attribute names.
15. Theta-join
• If we want to combine tuples from two relations where the
combination condition is not simply the equality of shared
attributes then it is convenient to have a more general form of
join operator, which is the θ-join (or theta-join).
• It can be written as :
where a and b are attribute names, θ is a binary relation
in the set {<, ≤, =, >, ≥}, v is a value constant
16. Example
• Consider tables Car and Boat which list models of cars and boats
and their respective prices. Suppose a customer wants to buy a car
and a boat, but she does not want to spend more money for the boat
than for the car. Relation is CarPrice ≥ BoatPrice.