SQL Database 4 Table Join's

create database GGG

use GGG

create table Location(id int primary key,name varchar(255))
create table Department(id int primary key , name varchar(255),loc int foreign key references location(id))
create table Employeee(id int primary key , name varchar(255),did int foreign key references Department(id))
create table Salary(id int primary key,sal int,eid int foreign key references Employeee(id))

insert into Location values(1,'London'),(2,'America'),(3,'Australia'),(4,'New zeland'),(5,'China'),(6,'Japan')
insert into Department values(1,'Marketing',1),(2,'SRO',2),(3,'Placement',3),(4,'Reseption',4),(5,'Liborty',5),(6,'Lab',6)
insert into Employeee values(1,'Akhlas',1),(2,'Humza',2),(3,'Nabeel',3),(4,'Usman',4),(5,'Ahtisham',5),(6,'Arsalan',6)
insert into Salary values(1,10000,1),(2,20000,2),(3,30000,3),(4,40000,4),(5,50000,5),(6,60000,6)

select * from Location
select * from Department
select * from Employeee
select * from Salary

select E.name AS ENAME ,D.name AS DNAME ,L.name AS LOCATION ,S.SAL AS SALARY from Employeee E join
Department D on E.did=D.id join Location L on D.loc=l.id join Salary S on S.eid=E.id

Comments