Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure...

30
Bordoloi and Bordoloi and Bock Bock Chapter 6 : JOINS Chapter 6 : JOINS

Transcript of Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure...

Page 1: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Chapter 6 : JOINSChapter 6 : JOINS

Page 2: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

A TYPICAL JOIN OPERATIONA TYPICAL JOIN OPERATION

• Following figure displays the Following figure displays the employee employee and and department department tables. tables.

• The figure illustrates the concept of a JOIN The figure illustrates the concept of a JOIN operation by connecting columns within each table operation by connecting columns within each table with a line.with a line.

• One line connects the One line connects the employeeemployee table's table's emp_dpt_numberemp_dpt_number column with the column with the departmentdepartment table's table's dpt_nodpt_no column. column.

• A second line connects the A second line connects the employeeemployee table's table's emp_ssnemp_ssn column to the column to the departmentdepartment table's table's dep_mgrssndep_mgrssn column. column.

Page 3: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

A TYPICAL JOIN OPERATIONA TYPICAL JOIN OPERATION

Page 4: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

• We will begin our study of JOIN operations by We will begin our study of JOIN operations by focusing on the relationship between the focusing on the relationship between the employeeemployee and and departmentdepartment tables represented by the common tables represented by the common department number values.department number values.

• Our first query lists employee names and Our first query lists employee names and department numbers. This query only retrieves department numbers. This query only retrieves data from the single data from the single employeeemployee table. table.

Page 5: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

SELECT emp_last_name "Last Name", SELECT emp_last_name "Last Name", emp_first_name "First Name",emp_first_name "First Name",

emp_dpt_number "Department"emp_dpt_number "Department"FROM employee;FROM employee;Last Name First Name DepartmentLast Name First Name Department------------- -------------- --------------------------- -------------- --------------Bordoloi Bijoy 1Bordoloi Bijoy 1Joyner Suzanne 3Joyner Suzanne 3Zhu Waiman 7Zhu Waiman 7more rows will be displayed . . .more rows will be displayed . . .

Page 6: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

• A large organization can have dozens or even A large organization can have dozens or even hundreds of departments. Thus, the numbers hundreds of departments. Thus, the numbers displayed in the department column shown above displayed in the department column shown above may not be very meaningful. may not be very meaningful.

• Suppose you want the department names instead Suppose you want the department names instead of the department numbers to be listed.of the department numbers to be listed.

• The department names are mentioned in the The department names are mentioned in the “Department” table.“Department” table.

• Hence we need to join the “Employee” and the Hence we need to join the “Employee” and the “Department” tables to get the required results“Department” tables to get the required results

Page 7: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

SELECT emp_last_name "Last Name", SELECT emp_last_name "Last Name", emp_first_name "First Name", emp_first_name "First Name", dpt_name "Department Name" dpt_name "Department Name" FROM employee, departmentFROM employee, departmentWHERE employee.emp_dpt_number = department.dpt_no;WHERE employee.emp_dpt_number = department.dpt_no;Last Name First Name Department NameLast Name First Name Department Name------------- ------------- ----------------------------------- ------------- ----------------------Bordoloi Bijoy HeadquartersBordoloi Bijoy HeadquartersJoyner Suzanne Admin and RecordsJoyner Suzanne Admin and RecordsZhu Waiman ProductionZhu Waiman Productionmore rows will be displayed . . .more rows will be displayed . . .

Page 8: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

• Following Table shows two tables simply named Following Table shows two tables simply named Table_1 and Table_2. Table_1 and Table_2.

• Each table has a single column named Col_1. Each Each table has a single column named Col_1. Each table also has three rows with simple alphabetic table also has three rows with simple alphabetic values stored in the Col_1 column.values stored in the Col_1 column.

Table_1 Table_2 Table_1 Table_2

COL_1COL_1

aa

bb

cc

COL_1COL_1

aa

bb

cc

Page 9: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS

SELECT *SELECT *FROM table_1, table_2;FROM table_1, table_2;

COL_1 COL_1COL_1 COL_1-------- ----------------- ---------

aa aab b aac c aaa a bbb b bbc c bba a ccb b cccc cc

Page 10: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINSJOINS• The first row of the “table_1” table was joined with The first row of the “table_1” table was joined with everyevery

row in the “table_2” table.row in the “table_2” table.

• A Cartesian product may not be useful and could be A Cartesian product may not be useful and could be misleading.misleading.

• Always include a WHERE clause in your JOIN statements.Always include a WHERE clause in your JOIN statements.

SELECT *SELECT *

FROM FROM table_1, table_2;table_1, table_2;WHERE table_1.col_1 = table_2.col_1;WHERE table_1.col_1 = table_2.col_1;

col_1 col_1col_1 col_1 -------- -------- -------- --------

a aa a bb b b

cc c c

Page 11: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOIN OPERATION RULESJOIN OPERATION RULES

JOINS and the SELECT ClauseJOINS and the SELECT Clause

• A JOIN query always begins with a SELECT A JOIN query always begins with a SELECT clause. clause.

• List the columns to be displayed in the result table List the columns to be displayed in the result table after the SELECT keyword. after the SELECT keyword.

• The result table column order reflects the order in The result table column order reflects the order in which column names are listed in the SELECT which column names are listed in the SELECT clause. clause.

• To modify the order in which column names are To modify the order in which column names are listed, simply rearrange the order of the column listed, simply rearrange the order of the column listing in the SELECT clause. listing in the SELECT clause.

Page 12: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

ExampleExample

SELECT dpt_name "Department Name",SELECT dpt_name "Department Name", emp_last_name "Last Name",emp_last_name "Last Name", emp_first_name "First Name"emp_first_name "First Name"FROM employee e, department dFROM employee e, department dWHERE e.emp_dpt_number = d.dpt_no AND WHERE e.emp_dpt_number = d.dpt_no AND

e.emp_dpt_number = 7;e.emp_dpt_number = 7;

Department Name Last Name First NameDepartment Name Last Name First Name---------------------- -------------- ------------------------------------- -------------- ---------------Production Zhu WaimanProduction Zhu WaimanProduction Bock DouglasProduction Bock DouglasProduction Joshi DineshProduction Joshi DineshProduction Prescott SherriProduction Prescott Sherri

Page 13: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINS and the FROM ClauseJOINS and the FROM Clause

• Any SELECT statement that has two or more table names Any SELECT statement that has two or more table names listed in a FROM clause is a JOIN query.listed in a FROM clause is a JOIN query.

• By definition, a JOIN operation retrieves rows from two or By definition, a JOIN operation retrieves rows from two or more tables. more tables.

• Always the FROM clause is used to list the tables from Always the FROM clause is used to list the tables from which columns are to be retrieved by a JOIN query.which columns are to be retrieved by a JOIN query.

• The FROM clause listing has a limit of 16 table names. The FROM clause listing has a limit of 16 table names. • The order of table name listings is irrelevant to the The order of table name listings is irrelevant to the

production of the result table with the one exception – that production of the result table with the one exception – that is, if you use an asterisk (*) in the SELECT clause, then is, if you use an asterisk (*) in the SELECT clause, then the column order in the result table reflects the order in the column order in the result table reflects the order in which tables are listed in the FROM clause. which tables are listed in the FROM clause.

Page 14: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

JOINS and the WHERE ClauseJOINS and the WHERE Clause

• The WHERE clause specifies the relationship The WHERE clause specifies the relationship between tables listed in the FROM clause. between tables listed in the FROM clause.

• It also restricts the rows displayed in the result It also restricts the rows displayed in the result table.table.

• The most commonly used JOIN operator is the The most commonly used JOIN operator is the "equal" (=) sign."equal" (=) sign.

Page 15: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

QUALIFYING COLUMN NAMESQUALIFYING COLUMN NAMES

• When column names are ambiguous (the column names When column names are ambiguous (the column names

used are from more than one table) you must qualify themused are from more than one table) you must qualify them SELECT *SELECT *FROM table_1, table_2FROM table_1, table_2WHERE col_1 = col_1;WHERE col_1 = col_1;

• This query is This query is WRONGWRONG, Oracle Server would reject this , Oracle Server would reject this query and generate the error message "ambiguous object.“query and generate the error message "ambiguous object.“

Error at line 3:Error at line 3:

ORA - 00918 : column ambiguously definedORA - 00918 : column ambiguously defined

Page 16: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

QUALIFYING COLUMN NAMESQUALIFYING COLUMN NAMES

• This error message tells you that you have included a This error message tells you that you have included a column name somewhere in the query that exists in more column name somewhere in the query that exists in more than one table listed in the FROM clause.than one table listed in the FROM clause.

• Here the error is in the WHERE clause; however, it is also Here the error is in the WHERE clause; however, it is also possible to make a similar error in the SELECT clause.possible to make a similar error in the SELECT clause.

• The SELECT statement shown below fails to qualify the The SELECT statement shown below fails to qualify the col_1 name in the SELECT clause, and Oracle again col_1 name in the SELECT clause, and Oracle again produces the ORA-00918 error message.produces the ORA-00918 error message.

SELECT col_1SELECT col_1FROM table_1, table_2FROM table_1, table_2WHERE table_1.col_1 = table_2.col_1;WHERE table_1.col_1 = table_2.col_1;ERROR at line 1:ERROR at line 1:ORA-00918: column ambiguously definedORA-00918: column ambiguously defined

Page 17: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

QUALIFYING COLUMN NAMESQUALIFYING COLUMN NAMES

• An ambiguous column name is qualified by using An ambiguous column name is qualified by using the DOT (the DOT (..) connector to connect the table name and ) connector to connect the table name and column name.column name.

• Sometimes it is easier to qualify column names by Sometimes it is easier to qualify column names by using table alias names. using table alias names.

• Often, a single letter is used as an identifier to Often, a single letter is used as an identifier to reduce keystroke requirements . reduce keystroke requirements .

SELECT dpt_name "Department Name", SELECT dpt_name "Department Name", emp_last_name "Last Name",emp_last_name "Last Name", emp_first_name "First Name"emp_first_name "First Name"FROM employee e, department dFROM employee e, department dWHERE e.emp_dpt_number = d.dpt_no AND e.emp_dpt_number = 7;WHERE e.emp_dpt_number = d.dpt_no AND e.emp_dpt_number = 7;

Page 18: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

QUALIFYING COLUMN NAMESQUALIFYING COLUMN NAMES

• The use of the letters "e" and "d" is completely The use of the letters "e" and "d" is completely arbitrary; "t1" and "t2" or any other unique aliases arbitrary; "t1" and "t2" or any other unique aliases could have been used.could have been used.

• The important points to learn are:The important points to learn are:– The alias must follow a table name.The alias must follow a table name.– Use a space to separate a table name and its alias.Use a space to separate a table name and its alias.– The alias must be unique within the SELECT The alias must be unique within the SELECT

statement.statement.• If the column names are not identical you are not If the column names are not identical you are not

required to qualify them, although you still might required to qualify them, although you still might want to for documentation purposeswant to for documentation purposes

Page 19: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Joining More Than Two TablesJoining More Than Two Tables

• While the examples given thus far have joined While the examples given thus far have joined rows from two tables, you can specify up to 16 rows from two tables, you can specify up to 16 tables in a JOIN operation.tables in a JOIN operation.

• The more tables that are included in a JOIN The more tables that are included in a JOIN operation, the longer the query will take to operation, the longer the query will take to process, especially when the tables are large with process, especially when the tables are large with millions of rows per table. millions of rows per table.

Page 20: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Joining More Than Two TablesJoining More Than Two Tables

• The example shown in following figure joins three The example shown in following figure joins three tables to produce a result table based on two different tables to produce a result table based on two different relationships. relationships.

Page 21: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Joining More Than Two TablesJoining More Than Two Tables

• The SELECT statement to join the tables The SELECT statement to join the tables depicted in the figure is shown here. depicted in the figure is shown here.

SELECT emp_last_name "Last Name", SELECT emp_last_name "Last Name", emp_first_name "First Name", emp_first_name "First Name", 1.10*emp_salary "Raised Salary", p.pro_name "Project"1.10*emp_salary "Raised Salary", p.pro_name "Project"FROM employee e, assignment a, project pFROM employee e, assignment a, project pWHERE e.emp_ssn = a.work_emp_ssn ANDWHERE e.emp_ssn = a.work_emp_ssn AND a.work_pro_number = p.pro_number ANDa.work_pro_number = p.pro_number AND p.pro_name = 'Inventory';p.pro_name = 'Inventory';

Last Name First Name Raised Salary ProjectLast Name First Name Raised Salary Project--------------- --------------- ---------------- -------------------------- --------------- ---------------- -----------Zhu Waiman $47,300 InventoryZhu Waiman $47,300 InventoryMarkis Marcia $27,500 InventoryMarkis Marcia $27,500 InventoryAmin Hyder $27,500 InventoryAmin Hyder $27,500 Inventory

Page 22: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Joining Tables by Using Two ColumnsJoining Tables by Using Two Columns

• The diagram depicts the relationship at a The diagram depicts the relationship at a university where students enroll in course university where students enroll in course sections. sections.

Page 23: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

Joining Tables by Using Two ColumnsJoining Tables by Using Two Columns

• The SELECT statement that accomplishes the The SELECT statement that accomplishes the JOIN based on two columns is shown below. JOIN based on two columns is shown below.

• This situation arises when the related tables This situation arises when the related tables have have composite primary keycomposite primary key columns. columns.

SELECT s.course_title "Course Title", SELECT s.course_title "Course Title",

e.student_ssn "Student SSN"e.student_ssn "Student SSN"

FROM enrollment e, section sFROM enrollment e, section s

WHERE e.course_number = s.course_number ANDWHERE e.course_number = s.course_number AND

e.section_number = s.section_number;e.section_number = s.section_number;

Page 24: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

OUTER JOIN OperationsOUTER JOIN Operations

• Oracle also supports what is called an outer-Oracle also supports what is called an outer-join. This means that a row will appear in the join. This means that a row will appear in the joined table even though there is no matching joined table even though there is no matching value in the table to be joined. value in the table to be joined.

• Suppose you want to know the names of the Suppose you want to know the names of the employees regardless of whether they have employees regardless of whether they have dependents or not. You can use the outer join as dependents or not. You can use the outer join as follows follows

Page 25: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

OUTER JOIN OperationsOUTER JOIN Operations

• The plus sign in parentheses (+) tells Oracle to The plus sign in parentheses (+) tells Oracle to execute an OUTER JOIN operation. execute an OUTER JOIN operation.

• Further, it is the Further, it is the dependentdependent table that is being table that is being outer-joined to the outer-joined to the employeeemployee table because some table because some employees will not have dependents.employees will not have dependents.

SELECT emp_last_name "Last Name", SELECT emp_last_name "Last Name", emp_first_name "First Name", emp_first_name "First Name",

dep_name "Dependent", dep_name "Dependent", dep_relationship "Relationship"dep_relationship "Relationship"FROM employee e, dependent dFROM employee e, dependent dWHERE e.emp_ssn = d.dep_emp_ssn(+);WHERE e.emp_ssn = d.dep_emp_ssn(+);

Page 26: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

SELECT emp_last_name "Last Name",SELECT emp_last_name "Last Name", emp_first_name "First Name", emp_first_name "First Name", dep_name "Dependent",dep_name "Dependent", dep_relationship "Relationship"dep_relationship "Relationship"FROM employee e, dependent dFROM employee e, dependent dWHERE e.emp_ssn = d.dep_emp_ssn(+);WHERE e.emp_ssn = d.dep_emp_ssn(+);

Last Name First Name Dependent RelationshipLast Name First Name Dependent Relationship--------------- --------------- -------------- --------------------------- --------------- -------------- ------------Bordoloi BijoyBordoloi BijoyJoyner Suzanne Allen SPOUSEJoyner Suzanne Allen SPOUSEZhu Waiman Andrew SONZhu Waiman Andrew SONZhu Waiman Jo Ellen DAUGHTERZhu Waiman Jo Ellen DAUGHTERZhu Waiman Susan SPOUSEZhu Waiman Susan SPOUSEMarkis MarciaMarkis MarciaAmin HyderAmin HyderBock Douglas Deanna DAUGHTERBock Douglas Deanna DAUGHTERBock Douglas Jeffery SONBock Douglas Jeffery SONBock Douglas Mary Ellen SPOUSEBock Douglas Mary Ellen SPOUSEJoshi DineshJoshi DineshPrescott SherriPrescott Sherri12 rows selected.12 rows selected.

Page 27: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

OUTER JOINS and NULL values OUTER JOINS and NULL values

• Management might desire a listing of employees Management might desire a listing of employees with no dependents in order to satisfy some with no dependents in order to satisfy some governmental reporting requirement. governmental reporting requirement.

• We can take advantage of the fact that the We can take advantage of the fact that the dep_namedep_name column will be NULL for employees column will be NULL for employees with no dependents, and simply add a criteria to with no dependents, and simply add a criteria to the WHERE clause to include employees where the WHERE clause to include employees where the the dep_namedep_name column is NULL. column is NULL.

Page 28: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

OUTER JOINS and NULL values OUTER JOINS and NULL values

SELECT emp_last_name "Last Name", emp_first_name "First SELECT emp_last_name "Last Name", emp_first_name "First Name"Name"

FROM employee e, dependent dFROM employee e, dependent d

WHERE e.emp_ssn = d.dep_emp_ssn(+) ANDWHERE e.emp_ssn = d.dep_emp_ssn(+) AND

d.dep_name IS NULL;d.dep_name IS NULL;

Last Name First NameLast Name First Name

--------------- ------------------------------ ---------------

Bordoloi BijoyBordoloi Bijoy

Markis MarciaMarkis Marcia

Amin HyderAmin Hyder

Joshi DineshJoshi Dinesh

Prescott SherriPrescott Sherri

Page 29: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

SELF-JOIN OperationsSELF-JOIN Operations

• A SELF JOIN operation is used to produce a A SELF JOIN operation is used to produce a result table when the relationship of interest result table when the relationship of interest exists among rows that are stored within a exists among rows that are stored within a single table. single table.

Page 30: Bordoloi and Bock Chapter 6 : JOINS. Bordoloi and Bock A TYPICAL JOIN OPERATION Following figure displays the employee and department tables.Following.

Bordoloi and BockBordoloi and Bock

SELF-JOIN OperationsSELF-JOIN Operations

SELECT e1.emp_last_name || ', ' || e1.emp_first_name "Supervisor",SELECT e1.emp_last_name || ', ' || e1.emp_first_name "Supervisor",

e2.emp_last_name || ', ' || e2.emp_first_name "Employee"e2.emp_last_name || ', ' || e2.emp_first_name "Employee"

FROM employee e1, employee e2FROM employee e1, employee e2

WHERE e1.emp_ssn = e2.emp_superssn;WHERE e1.emp_ssn = e2.emp_superssn;

Supervisor EmployeeSupervisor Employee

---------------------------- ----------------------------------------------- -------------------

Bordoloi, Bijoy Joyner, SuzanneBordoloi, Bijoy Joyner, Suzanne

Bordoloi, Bijoy Zhu, WaimanBordoloi, Bijoy Zhu, Waiman

Joyner, Suzanne Markis, MarciaJoyner, Suzanne Markis, Marcia

Joyner, Suzanne Amin, HyderJoyner, Suzanne Amin, Hyder

Zhu, Waiman Bock, DouglasZhu, Waiman Bock, Douglas

Zhu, Waiman Joshi, DineshZhu, Waiman Joshi, Dinesh

Zhu, Waiman Prescott, SherriZhu, Waiman Prescott, Sherri