http://www.technicalpage.net/search/label/SQL

>> CROSS JOIN


CROSS JOIN

In cross join, either you do not mention the join condition or there is no join condition between the tables being joined.  So the result will be Cartesian product of the tables being joined.

Let's do the cross join of below two tables:

EMP_DATA
NAME
POSITION
SALARY
ADAMS
SALESMAN
1100
JAMES
DEALER
1300
MILLER
CLERK
1300

DEPT_DATA
DEPTNUM
DEPTNAME
LOCATION
30
SALES
CHICAGO
40
OPERATIONS
BOSTON
70
Marketing
DENVER

Syntax:
SELECT  {DESIRED  COLUMNS  OR  ALL  COLUMNS}  FROM {TABLE1}  CROSS  JOIN  {TABLE2} ;

OR

SELECT  {DESIRED  COLUMNS  OR  ALL  COLUMNS}  FROM  {TABLE1} , {TABLE2} ;

Query:
SELECT  *  FROM EMP_DATA  CROSS JOIN  DEPT_DATA ;

OR

SELECT  *  FROM EMP_DATA , DEPT_DATA ;

NAME
POSITION
SALARY
DEPTNUM
DEPTNAME
LOCATION
ADAMS
SALESMAN
1100
30
SALES
CHICAGO
ADAMS
SALESMAN
1100
40
OPERATIONS
BOSTON
ADAMS
SALESMAN
1100
70
Marketing
DENVER
JAMES
DEALER
1300
30
SALES
CHICAGO
JAMES
DEALER
1300
40
OPERATIONS
BOSTON
JAMES
DEALER
1300
70
Marketing
DENVER
MILLER
CLERK
1300
30
SALES
CHICAGO
MILLER
CLERK
1300
40
OPERATIONS
BOSTON
MILLER
CLERK
1300
70
Marketing
DENVER


NEXT

Go To Main SQL Page



.

No comments:

Post a Comment