Tuesday, February 19, 2013

Inner Joins and Cartesian Product

Inner joins
An inner join returns the rows that satisfy the join condition. For example say we want to list the name and department name for each employee. To do this we would use the following query:

SELECT E.FNAME, E.LNAME, D.NAME
FROM EMPLOYEE E, DEPARTMENT D
WHERE E.DEPT_ID = D.DEPT_ID;


Cartesian Product
If we don’t specify the join condition while joining the tables, oracle combines each row from the first table with each row of the second table. This type of result set is called as a Cartesian product.

For example:
SELECT E.FNAME, E.LNAME, D.NAME
FROM EMPLOYEE E, DEPARTMENT D;

No comments:

Post a Comment