Presentation is loading. Please wait.

Presentation is loading. Please wait.

S. KWAN Relational Join1 A Relational Join operation could be thought of as being implemented with a series of operations: CARTESIAN PRODUCT RELATIONAL.

Similar presentations


Presentation on theme: "S. KWAN Relational Join1 A Relational Join operation could be thought of as being implemented with a series of operations: CARTESIAN PRODUCT RELATIONAL."— Presentation transcript:

1 S. KWAN Relational Join1 A Relational Join operation could be thought of as being implemented with a series of operations: CARTESIAN PRODUCT RELATIONAL SELECT RELATIONAL PROJECT ORDERING

2 S. KWAN Relational Join2 The Cartesian Product (or simply, Product) of two tables is written as: A x B or A Times B This operation does NOT require the two tables to be UNION compatible. The operation will attach each tuple of A to each tuple of B. That is, the new table is created by forming all possible combinations of rows from A and B. If table A has m rows and B has n rows, the resultant table will have m x n rows. Some of these rows are meaningless.

3 S. KWAN Relational Join3 Q02: Supplier who supply Project “J1” SELECT SUPPLIER.[S#] AS [SUPPLIER NUMBER], SUPPLIER.SNAME AS NAME SUPPLIER.SNAME AS NAME FROM SUPPLIER, SPJ WHERE SUPPLIER.[S#] = SPJ.[S#] AND SPJ.[J#]="J1" ORDER BY SUPPLIER.[S#]; Relational Project Cartesian Product Relational Select Ordering Join Criteria

4 S. KWAN Relational Join4 The Cartesian Product is formed first: SELECT * FROM SUPPLIER, SPJ; Many rows not shown here 5 x 24 = 120 rows

5 S. KWAN Relational Join5 Then the Relational Select’s are performed: SELECT * FROM SUPPLIER, SPJ WHERE SUPPLIER.[S#] = SPJ.[S#] AND SPJ.[J#] = “J1”;

6 S. KWAN Relational Join6 Then the Relational Project’s are performed: SELECT SUPPLIER.[S#] AS [SUPPLIER NUMBER], SUPPLIER.SNAME AS NAME FROM SUPPLIER, SPJ WHERE SUPPLIER.[S#]=SPJ.[S#] AND SPJ.[J#]="J1";

7 S. KWAN Relational Join7 Finally, the Ordering is performed: (no apparent effect in this example) SELECT SUPPLIER.[S#] AS [SUPPLIER NUMBER], SUPPLIER.SNAME AS NAME FROM SUPPLIER, SPJ WHERE SUPPLIER.[S#]=SPJ.[S#] AND SPJ.[J#]="J1” ORDER BY SUPPLIER.[S#]; Return to to SPJSQL


Download ppt "S. KWAN Relational Join1 A Relational Join operation could be thought of as being implemented with a series of operations: CARTESIAN PRODUCT RELATIONAL."

Similar presentations


Ads by Google