create database test_demo1
go
use test_demo1
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 'Shrikant',1,1
union all
select 'Sam',2,2
go
--Inner join :
--select * from
--<tab1 name> <alias>
--<join type >
--<tab2 name> <alias>
--on <condition>
select emp.employeeId,emp.employeeName,Cmp.Name [companyName] ,dept.name [Department Name] from
EmployeeDetail emp
inner join
Company cmp
on emp.companyId=cmp.companyId
inner join
Department dept
on emp.departmentId=dept.departmentId
No comments:
Post a Comment