0% found this document useful (0 votes)
80 views7 pages

Date:19102121: Ex - No: 3

1. The document discusses nested queries in RDBMS including different types like independent nested queries and correlated subqueries. 2. Examples are provided to demonstrate various nested query operations like IN, EXISTS, UNION, INTERSECT etc. along with sample tables, data and queries. 3. The results of executing nested queries on the sample tables and data are displayed.

Uploaded by

Ravichandran B
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)
80 views7 pages

Date:19102121: Ex - No: 3

1. The document discusses nested queries in RDBMS including different types like independent nested queries and correlated subqueries. 2. Examples are provided to demonstrate various nested query operations like IN, EXISTS, UNION, INTERSECT etc. along with sample tables, data and queries. 3. The results of executing nested queries on the sample tables and data are displayed.

Uploaded by

Ravichandran B
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/ 7

EX.

NO: 3
DATE:19102121 NESTED QUERIEs

AIM
To execute and verify nested queries in RDBMS

PROCEDURE
A. NESTED QUERIES

nLe>ted QUUDU D, a QUPY WHTHen tnude a ueg.The

Tebult 08net qLey ubee n ererutOn OUtei Quey

Types
1. Independent Nested Queries:
n Tndependenk nebh Qupy, qLEuy eseution Statts erom

the neh most queky t6 outtumoshQueuy, The exeelkio n t n n e


ndependenk Oukot quD. 6ut the ebult o Unnen ouey
nexecuuribn ROuko ueuy
2. Co-related sub Query::
Uo-7elnE Sub-quey, the oukpu e inng1 QueY4
dependb on the 60 Ohi ch ts being Covtontu
eecuted n outo
auueuy
Command Definition
Set Membership:
In (connective) an Opoaket Checrb 15 a
etoin Valuue in thre
abe ts 1eduuad by a Sub-qusy i no
not In (connective) von oPøatei uteS Out au tro Nous (oteRti
tugo
to the alues not iebend in The tablo netwn
ey the Sub -ueuy

sets
Set Comparison: To comparc
,Some Gome mubk maeh OLk One 1Molu tn the Sub4i Lph
dnd mubt be piceeded by Compuuson OPetako
all
mubk na kch cul dows in the Sub-quet4
exists
Not exists
T 5 ubed lo Febt o fue xebtence ony 1ecod
w t u cheek Hhe Sub-qpuo-uy r Hhe i6w
e t tence and ( heue ate no 4ow, then c o
r Hue alwo
unique
enbuwueb all hue Uatupb ate drtfoment

not unique TF eueuJ one TOW U e l a k k s n Ute l o

Cuuque, then it etwun a ljue tnlue


with
Mouides a uny og delini ti a tempojayielakio
whgse drinition ts auallnubLe onty totho verytn
Which he claube Wh OCutS.

Create a table called EMP with the following structure.


Name Type
----
---

EMPNO NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(10)
DEPTNO NUMBER(3)
SALARY NUMBER(7.2)
Create a table called DEPT with the
following structure.
Name Type

DEPTNO NUMBER(2)
DNAME VARCHAR2(10)
LOC VARCHAR2(10)

Insert the following values in both the tables.


EMPNO ENAME JOB DEPTNO SAL

Mathi AP 10000
ASP
Arjun 12000
Gugan ASP 20000
4 Karthik AP 15000
DEPTN0 DNAME LOC
-----

ACCOUNTING NEW YORKK


RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

Nested Queries:
Q1: Display all employee names and salary whose salary is greater than
salary of the company and job title starts with M'. AG
minimum
Query: : Seleck
name,Sclay om emp wnuee Sculay> (Selere min(Sala,
uememe Sand iob uee as
Output:

Q2: Issue a
Query: to find all the employees who work in the same job as Arjun.

Query:: Seleet nomn emp wherue aob uee CSelett job uo m emp
whee emme = ayun'),
Output:

03: Issue a
Query: to display information about employees who earn more than any
employee in dept 1.

Query: SeleeE upn emplbyee where Salt > Some CSelece Salnu
Pvern ene whwe depeno=1)
Output:

Q4: Union

Query
SwrE wm dept wion Sptett
em dept-1
Output:

Q4: Union all

Query
SeLect sm depe nional Selere n dept

Output:

Q4: Intersect

Query
Select en depe tnoubert SeLEEE Bem depe

Output:

Q4: minus

Query
Seerte ern dlept Minus Seleel Bhem depE1

Output:

Q4: Group by (Counk no Cmpleyeeb in abP sob


Query Seueet ounk (empno uom emp ocup by Job haung

JcbASP

Output:

Q4: order by CSeou toble-emp base n dept_umin des enp no a a )

ry
bm emp Otu 6y dept no debC, enp.no abe

Output:

Q4: GROUP BY... HAVING....ORDER BY Cdiplay dept flo 4 Salaty babed on


(Tnouenbe n cil C& depE andl uuh Soit tube abinput displauy deptnc motethan
Query Galevuy 3o cce
Seek dpeno iem CSeleck dept no, Salau Brem emp cider bs
depe no)Puoup by dept no hoving Sum (Salnoy) >3o000

Output:

MARK ALLOCATION
CONTINUOUS INTERNAL ASSESSMENTT
Conduct of Experiment (20)
Record & Result (15)

Viva (15)

Total (50)

Signature ofthe Faculty with Date


EName ScuLb
Coyun 2 6oo

9gan 20 000

Empno Ename Tob Dept no


Salby
Oyun CuP 2 20oo

20006
9Lugon
3. Empno Ename Joo Deptnd Sculby
cusP 2 2000D

Kocuhi.k ap
CHun asP 2 2 000

Dept no Dname LoCatovM

actountng newyouR
eSenuch dalunb

Finanee New deh

mauPeing Chenntu

30 Saueb chi Cug o

openakin19 boston

5 Depe np Daame LoCetidn

attounkng
eenuth dnlleus

SalLe chu Cgo


30
Opevaking oslon

OLttounkn9 NEupyotR
ebeahth douad

3 Fiuance rUew delLu

meURettnq chenneu
Dept no Drame LoCeutien
touunt ing reuW yoR

ebeahcn drun

Depe no Dnaume Lolate


Suled Chicago
HO opeates boSken

Count (Empno

Deptna Ennme

ayun
gunn
mauth

KathicR

lo. DeptNo

You might also like