0% found this document useful (0 votes)
187 views2 pages

SALESPERSON (SSN, Name, Start - Year, Dept - No) TRIP (SSN, From - City, To - City, Departure - Date, Return - Date, Trip - Id) EXPENSE (Trip - Id, Account#, Amount)

This document discusses different types of join operations in SQL: 1. EQUIJOIN joins two tables on equality comparisons between attributes. It returns tuples where the joined attributes have identical values. 2. NATURAL JOIN removes duplicate attributes from the join condition. It implicitly joins on attributes of the same name. 3. OUTER JOINs retain all tuples from one or both tables, padding missing values with NULL. Left/right outer joins keep all tuples from the left/right table, while full outer join keeps all tuples from both tables.

Uploaded by

kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views2 pages

SALESPERSON (SSN, Name, Start - Year, Dept - No) TRIP (SSN, From - City, To - City, Departure - Date, Return - Date, Trip - Id) EXPENSE (Trip - Id, Account#, Amount)

This document discusses different types of join operations in SQL: 1. EQUIJOIN joins two tables on equality comparisons between attributes. It returns tuples where the joined attributes have identical values. 2. NATURAL JOIN removes duplicate attributes from the join condition. It implicitly joins on attributes of the same name. 3. OUTER JOINs retain all tuples from one or both tables, padding missing values with NULL. Left/right outer joins keep all tuples from the left/right table, while full outer join keeps all tuples from both tables.

Uploaded by

kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

3b)

3a)
SALESPERSON(Ssn, Name, Start_year, Dept_no)
TRIP(Ssn, From_city, To_city, Departure_date, Return_date, Trip_id)
EXPENSE(Trip_id, Account#, Amount)
The schema of this question has the following two foreign keys:
1. The attribute SSN of relation TRIP that references relation SALESPERSON, and
2. The attribute Trip_ID of relation EXPENSE that references relation TRIP.
In addition, the attributes Dept_No of relation SALESPERSON and Account# of relation
EXPENSE are probably also foreign keys referencing other relations of the database not
mentioned in the question.
3b)
The JOIN operation, denoted by is used to combine related tuples from two relations
into single tuples.
EQUIJOIN Operation


The most common use of join involves join conditions with equality comparisons
only
 Such a join, where the only comparison operator used is =, is called an
EQUIJOIN.
 In the result of an EQUIJOIN we always have one or more pairs of attributes
(whose names need not be identical) that have identical values in every tuple.
NATURAL JOIN Operation

 Another variation of JOIN called NATURAL JOIN denoted by * was created to


get rid of the second (superfluous) attribute in an EQUIJOIN condition.
 Because one of each pair of attributes with identical values is superfluous
 The standard definition of natural join requires that the two join attributes, or each
pair of corresponding join attributes, have the same name in both relations.
 If this is not the case, a renaming operation is applied first.

Example: To apply a natural join on the DNUMBER attributes of DEPARTMENT and


DEPT_LOCATIONS, it is sufficient to write:

 DEPT_LOCS ¬ DEPARTMENT * DEPT_LOCATIONS


 Only attribute with the same name is DNUMBER
 An implicit join condition is created based on this attribute:
 DEPARTMENT.DNUMBER=DEPT_LOCATIONS.DNUMBER

The OUTER JOIN Operation


 In NATURAL JOIN and EQUIJOIN, tuples without a matching (or related) tuple are
eliminated from the join result
 Tuples with null in the join attributes are also eliminated
 This amounts to loss of information.
 A set of operations, called OUTER joins, can be used when we want to keep all the
tuples in R, or all those in S, or all those in both relations in the result of the join,
regardless of whether or not they have matching tuples in the other relation.
 The left outer join operation keeps every tuple in the first or left relation R in R S;
if no matching tuple is found in S, then the attributes of S in the join result are filled
or “padded” with null values.
 A similar operation, right outer join, keeps every tuple in the second or right relation
S in the result of R S.
A third operation, full outer join, denoted by keeps all tuples in both the left and the
right relations when no matching tuples are found, padding them with null values as needed.
3c)

You might also like