CREATE DATABASE demo_oueter_join
go
USE demo_oueter_join
go
CREATE TABLE company
(
companyid INT IDENTITY(1, 1),
NAME VARCHAR(100)
)
CREATE TABLE department
(
departmentid INT IDENTITY(1, 1),
NAME VARCHAR(100)
)
CREATE TABLE employeedetail
(
employeeid INT IDENTITY(1, 1),
employeename VARCHAR(100),
departmentid INT,
companyid INT
)
go
SELECT *
FROM company
SELECT *
FROM department
SELECT *
FROM employeedetail
go
INSERT INTO company
(NAME)
SELECT 'A'
UNION
SELECT 'B'
INSERT INTO department
(NAME)
SELECT 'X'
UNION
SELECT 'Y'
INSERT INTO employeedetail
(employeename,
departmentid,
companyid)
SELECT 'Paul',
1,
3
UNION ALL
SELECT 'Sam',
2,
2
go
--Inner join :
--select * from
--
--
--
--on
SELECT emp.employeeid,
emp.employeename,
Cmp.NAME [companyName],
dept.NAME [Department Name]
FROM employeedetail emp
INNER JOIN company cmp
ON emp.companyid = cmp.companyid
No comments:
Post a Comment