Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Gov

ernmentCol
legeofEngi
neer
ing,
Nagpur
Depar
tmentofComput
erSci
ence&Engi
neer
ing
Pr
act
icalLABManualSol
uti
ons(
2021-
22)
I
VthSemester

Subj
ect
:
DATABASEMANAGEMENTSYSTEM
Br
anch:CSE{DI RECTSECONDYEAR}
Name:VishalSur
eshKeshar
wani Enrol
mentNo./Rol
lno.74
Batch:B4. Subj
ectTeacher:Pr
of.Pr
iyaKhotel
e

Pr
act
ical
-7

Ai
m:-Toexecut
enest
edsubquer
ies
MySQLn estedsubqueries
AMy SQLsubqueryiscal
ledaninnerquer
ywhil
ethequer
ythatcont
ainsthesubquer
y
i
scalledanouterquer
y.Asubquerycanbeusedanywher
ethatexpr
essionisusedand
mustbeclosedinparent
heses.

Forexample,thefol
l
owingquer
yusesasubquer
ytor
etur
ntheempl
oyeeswhowor
kin
theof
ficeslocat
edintheUSA.

SELECT
l
astName,
fi
rst
NameFROM
employee
sWHERE
of
fi
ceCodeI N
(SELECT
offi
ceCode
FROM
offi
ce
s
WHERE
countr
y='USA'
);

 Thesubquer yret
urnsal
lof
fi
cecodesoft heof f
icesl
ocatedintheUSA.
 Theout erquer
yselect
sthelastnameandf i
rstnameofempl oyeeswho
workintheoffi
ceswhoseofficecodesar
eint heresul
tsetretur
nedby
thesubquery.

1
1
Quer
y1:Sel
ectt
heNameoft
heempl
oyeehav
ingMax(
wor
king_
hour
s).

Whenexecuti
ngthequery,
My SQLev
aluat
est
hesubquer
yfi
rstandusest
her
esul
tof
t
hesubqueryfort
heouterquery.
Let
'st
akeat
abl
e"empl
oyeet
abl
e"t
abl
e,havi
ngt
hef
oll
owi
ngdat
a.
Quer
y2:
Sel
ect
theNameanddepar
tment
oft
heempl
oyeehav
ingMi
n(Sal
ary)
.

Concl
usi
on:-Hencewesuccessf
ull edt
yexecut ost
udyandexecut
e
nest
edsubquer
ies.
1
1

You might also like