SQL-92 Cross Join Syntax : Cross Join « Table Join « SQL Server / T-SQL Tutorial






4> CREATE TABLE Departments(
5> Deptno   int         NOT NULL CONSTRAINT PK_dept_deptno PRIMARY KEY,
6> deptname varchar(15) NOT NULL
7> )
8> GO
1>
2> CREATE TABLE Jobs(
3> jobid   int         NOT NULL CONSTRAINT PK_jobs_jobid PRIMARY KEY,
4> jobdesc varchar(15) NOT NULL
5> )
6> GO
1>
2> INSERT INTO Departments VALUES(100, 'Java2sing')
3> INSERT INTO Departments VALUES(200, 'Production')
4> INSERT INTO Departments VALUES(300, 'Marketing')
5> INSERT INTO Departments VALUES(400, 'Management')
6> INSERT INTO Jobs VALUES(10, 'Java2s')
7> INSERT INTO Jobs VALUES(20, 'Oracle')
8> INSERT INTO Jobs VALUES(30, 'MySQL')
9> INSERT INTO Jobs VALUES(40, 'SqlServer')
10> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)
1>
2>
3> SELECT
4>   deptname,
5>   jobdesc
6> FROM
7>   Departments
8>   CROSS JOIN
9>   Jobs
10>
11> drop table Jobs
12> drop table Departments
13> GO
deptname        jobdesc
--------------- ---------------
Java2sing     Java2s
Production      Java2s
Marketing       Java2s
Management      Java2s
Java2sing     Oracle
Production      Oracle
Marketing       Oracle
Management      Oracle
Java2sing     MySQL
Production      MySQL
Marketing       MySQL
Management      MySQL
Java2sing     SqlServer
Production      SqlServer
Marketing       SqlServer
Management      SqlServer

(16 rows affected)
1>








4.2.Cross Join
4.2.1.SQL-92 Cross Join Syntax
4.2.2.Cross Join with itself
4.2.3.Matching Couples Using a Cross Join; Couples with Different Genders
4.2.4.it is the Cartesian product of all the rows from all tables participating in the SELECT statement