Mega Code Archive

 
Categories / MSSQL Tutorial / Table Join
 

SQL-92 Cross Join Syntax

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, 'rntsofting') 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, 'rntsoft') 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 --------------- --------------- rntsofting     rntsoft Production      rntsoft Marketing       rntsoft Management      rntsoft rntsofting     Oracle Production      Oracle Marketing       Oracle Management      Oracle rntsofting     MySQL Production      MySQL Marketing       MySQL Management      MySQL rntsofting     SqlServer Production      SqlServer Marketing       SqlServer Management      SqlServer (16 rows affected) 1>