Showing posts with label Example to use CROSS JOIN or CARTESIAN JOIN in SQL SERVER. Show all posts
Showing posts with label Example to use CROSS JOIN or CARTESIAN JOIN in SQL SERVER. Show all posts

Friday, August 1, 2014

CROSS JOIN or CARTESIAN JOIN in SQL SERVER


CREATE TABLE [dbo].[EmDetails]
(
                [EmpId] [int] IDENTITY(1,1) NOT NULL,
                [Name] [varchar](50) NULL,
                [Address] [varchar](200) NULL,
                [City] [varchar](50) NULL
)
INSERT INTO EmDetails (Name,Address,City) VALUES ('Lalit','#1234','Chandigarh')
INSERT INTO EmDetails (Name,Address,City) VALUES ('Raman','#4567','Panchkula')
INSERT INTO EmDetails (Name,Address,City) VALUES ('Arjun','#111','Noida')
INSERT INTO EmDetails (Name,Address,City) VALUES ('Rohan','#321','Delhi')
INSERT INTO EmDetails (Name,Address,City) VALUES ('Raghav','#675','Noida')

CREATE TABLE [dbo].[Tb_Dept]
(
                [DEPT_ID] [bigint] IDENTITY(1,1) NOT NULL,
                [DEPT_NAME] [varchar](50)NULL
)
INSERT INTO Tb_Dept (DEPT_NAME) VALUES ('HR')
INSERT INTO Tb_Dept (DEPT_NAME) VALUES ('IT')
INSERT INTO Tb_Dept (DEPT_NAME) VALUES ('SALES')

SELECT * FROM EmDetails CROSS JOIN Tb_Dept

SELECT * FROM EmDetails , Tb_Dept