0% found this document useful (0 votes)
25 views9 pages

DBMS 11.pdf - Ymyxkh

Uploaded by

harshitg8218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

DBMS 11.pdf - Ymyxkh

Uploaded by

harshitg8218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

subquery

it is also known as nested query or

inner query

seleit a from
students
where s id 101

student table
s id s.name age martis

1 A 22 87 a

a B 4
70
3 C 23 62
4 D 24 89 c

5 E 21 75
6 F 21 55
7 h 23 92

find all the student who scored greater


than 75

saltit A

foom students
where marks 775

I
the marks of the student whose
a find
skid is I 1

select marks
from students
where sb id L

a find all the student who scored greater


than the mark of St id L

student table st 52
student table
s.ids.name age man
s ids.name age
22 a many
Is an t 22
in
C 23
an 3 C 23

EE 5 E 21 75
4 I 23
t a is I
4 23 92

select st.name 51 marks


from students SL

join students 52
on s 2 marks 52 marks and 52.5 id L

find all the student who scored greater


7
than a

find the marks of the student whose


a
steid is I 1
saltit A

foom students for


where marki select marks fort
from students
where sb id L

subquery is used to get list values and


perform any operation based on result of
other query

ifs break complex logit in smaller


or manageable chunks
this is easier to understand and
more readable

generally it is used for small data set


and it is not good in terms of space
and performanie

selest the students who have marks


than the marks of students
greater average

selelt
from students
where marks select argemark
from students
employees table

e id t.name salary manager id


2 A 4511 7
5 B 40k 10

7 90k null
8 D ITR 15
10 9
E 20K
11 f 80k may
13 Cr 50k 6
6 ad 3011 7

9 bb nov 10

IT is 70k 6

find the id of the employees whose salary 30K

and whose manger left the company

when a manager
is left the company their information

is deleted from the employees table but the

their id still present in man_id

select e id
from employee
where salary 30,000

And manager id not


inf selent e id
from employees

break fill 9 14
instrator table

i id i.name salary dept id


2 A 41 103
5 B 40K 102
7 C For M e
8 D ite 10T X
10 ztk.to 70K
E 20k 102
11 f 50k mm in
13 a safe
105
6 ad 3011 102
9 bb 40 107
it is 70k 105

display instruitor who have salary


I name

greater than salary of all the instructor

of deaf id 105
ALL

select i_name
from instructor
where salary ALL selelt salary
from instructor
where dept id 105
525K 5011,701

select i_name
from instructor
where salary select max salad
from instmitor

display instructor name who have salary

greater than salary of any instructor

of deaf id 105

select i_name
from instructor
where salary Any selest salary
from instructor
where dept id 105

525K 5011,701
correlated query
with
if any query is related column
of other query

display instruitor name who have salary

greater than salary of avg salary of


their respective department
avg salary of a

spelitis departmen

stle it init name

from instructors a
where salary select avg salary
from instructor
where department id a department id

0 find the number of instructor where

depi id 110

Seleit countta
from instructor
where dep id 120
I find the number of instructor of all

department and with department_name 1

countta dirt id
selelt dept id
from instructor
inctuiter
group by dept id

seiest dept id a
from departments d
I

select count i intuitor id dept id


from instructor i
where department id d department id o inctuiter

You might also like