Cartesian Products
If a join condition is missing, you will end up joining all rows from one table with all the rows from the other table.
CREATE TABLE departments
(department_id number(10) not null,
department_name varchar2(50) not null,
CONSTRAINT departments_pk PRIMARY KEY (department_id)
);
insert into departments ( department_id, department_name )values(1,'Data Group' );
insert into departments ( department_id, department_name )values(2,'Purchasing' );
insert into departments ( department_id, department_name )values(3,'Call Center' );
insert into departments ( department_id, department_name )values(4,'Communication' );
CREATE TABLE employees
( employee_id number(10) not null,
last_name varchar2(50) not null,
job_id varchar2(30),
department_id number(10),
salary number(6),
manager_id number(6),
CONSTRAINT employees_pk PRIMARY KEY (employee_id),
CONSTRAINT fk_departments FOREIGN KEY (department_id)
REFERENCES departments(department_id)
);
insert into employees( employee_id, last_name, job_id, salary,department_id ,manager_id)
values( 1001, 'Lawson', 'MGR', 30000, 1, 1004);
insert into employees( employee_id, last_name, job_id, salary, department_id ,manager_id)
values( 1002, 'Wells', 'DBA', 20000, 2, 1005 );
insert into employees( employee_id, last_name, job_id, salary, department_id ,manager_id)
values( 1003, 'Bliss', 'PROG', 24000, 3, 1004);
insert into employees( employee_id, last_name, job_id, salary, department_id, manager_id)
values( 1004, 'Kyte', 'MGR', 25000 ,4, 1005);
insert into employees( employee_id, last_name, job_id, salary, department_id, manager_id)
values( 1005, 'Viper', 'PROG', 20000, 1, 1006);
insert into employees( employee_id, last_name, job_id, salary, department_id,manager_id)
values( 1006, 'Beck', 'PROG', 20000, 2, null);
insert into employees( employee_id, last_name, job_id, salary, department_id, manager_id)
values( 1007, 'Java', 'PROG', 20000, 3, 1006);
insert into employees( employee_id, last_name, job_id, salary, department_id, manager_id)
values( 1008, 'Oracle', 'DBA', 20000, 4, 1006);
SQL> select employee_id, last_name, department_name
2 from employees, departments;
EMPLOYEE_ID LAST_NAME DEPARTMENT_NAME
----------- --------------------------------------------------
1001 Lawson Data Group
1002 Wells Data Group
1003 Bliss Data Group
1004 Kyte Data Group
1005 Viper Data Group
1006 Beck Data Group
1007 Java Data Group
1008 Oracle Data Group
1001 Lawson Purchasing
1002 Wells Purchasing
1003 Bliss Purchasing
1004 Kyte Purchasing
1005 Viper Purchasing
1006 Beck Purchasing
1007 Java Purchasing
1008 Oracle Purchasing
1001 Lawson Call Center
1002 Wells Call Center
1003 Bliss Call Center
1004 Kyte Call Center
1005 Viper Call Center
1006 Beck Call Center
1007 Java Call Center
1008 Oracle Call Center
1001 Lawson Communication
1002 Wells Communication
1003 Bliss Communication
1004 Kyte Communication
1005 Viper Communication
1006 Beck Communication
1007 Java Communication
1008 Oracle Communication
32 rows selected.
SQL>
Home »
Oracle »
Select »
Oracle »
Select »
Join:
- Table Join
- Using Table name to reference duplicate names
- Table Alias
- Cartesian Products
- Join more than two tables
- Join Conditions and Join Types
- Outer Joins
- Left and Right Outer Joins
- Outer join Error
- Self Join
- Outer Self Join
- Inner Joins Using SQL/92
- Joins with USING Keyword
- Inner Joins with More than Two Tables Using SQL/92
- Inner Joins on Multiple Columns Using SQL/92
- Outer Joins in SQL/92 Syntax
- Self Joins Using SQL/92
- Cross Joins Using SQL/92
Related: