SlideShare a Scribd company logo
NESTED SUBQUERY
PREPARED BY
Ms.R.Ragavi -III-B.Sc - Information Technology
UNDER THE GUIDANCE OF
Mrs.P.Anusha M.Sc(IT).,M.Phil.,D.P.T.T.,(Ph.D).,
Assistant professor,
Department of Information Technology,
Bon secours college for women,
Thanjavur.
DEFINE NESTED SUBQUERY
• A Subquery or inner query or a Nested query is
a query within another SQL query and
embedded within the WHERE clause.
• A Common use of subqueries is to perform test
for set membership, make set comparisons, and
determine set cardinality by nesting of
subqueries in the WHERE clause.
USES
• A subquery is used to return data that will be used in
the main query as a condition to further restrict the
data to be retrieved.
• Subquery can be used with the SELECT , INSERT,
UPDATE , and DELETE statements along with the
operators like =,<,>,>=,<=, IN BETWEEN etc.
• Sub queries must be enclosed within parentheses.
• A subquery can have only one column in the SELECT
clause, unless multiple columns are in the main query for
the sub query to compare its selected columns.
• An ORDER BY COMMAND cannot to used in a
subquery.
• SQL provides a mechanism for nesting subqueries.
CUSTOMER
ID
NAME AGE ADDRESS SALARY
001 ANITHA 30 CHIDAMBARAM 20,000
002 SIVAKAMI 25 KUMBAKONAM 24,000
003 ALAMELU 26 NEYVELI 26,000
004 GEETHA 45 THANJAVUR 38,000
005 RANI 35 TRICHY 20,000
006 MALATHI 36 BANGALORE
007 GOPI 29 KERALA
SYNTAX
• Select column name from table name where column name
operator(select column name from table name where);
EXAMPLE
Select * from customers where customer_id IN (select customers_id
from customers where salary >=25000;
Customer _id Name Age Address Salary
003 Alamelu 26 Neyveli 26000
004 Geetha 45 Thanjavur 38000

More Related Content

What's hot

SQL Constraints
SQL ConstraintsSQL Constraints
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
Esmita Gupta
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
4. plsql
4. plsql4. plsql
4. plsql
Amrit Kaur
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
Raj Naik
 
join relation.pptx
join relation.pptxjoin relation.pptx
join relation.pptx
Anusha sivakumar
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
shekhar1991
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
Ravinder Kamboj
 

What's hot (20)

SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
joins in database
 joins in database joins in database
joins in database
 
4. plsql
4. plsql4. plsql
4. plsql
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
join relation.pptx
join relation.pptxjoin relation.pptx
join relation.pptx
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 

More from Anusha sivakumar

deadline.pptx
deadline.pptxdeadline.pptx
deadline.pptx
Anusha sivakumar
 
Evolution of Computers ppt.pptx
Evolution of Computers ppt.pptxEvolution of Computers ppt.pptx
Evolution of Computers ppt.pptx
Anusha sivakumar
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
Anusha sivakumar
 
PURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptxPURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptx
Anusha sivakumar
 
fundamental relation algebra.pptx
fundamental relation algebra.pptxfundamental relation algebra.pptx
fundamental relation algebra.pptx
Anusha sivakumar
 
DBMS ARCHITECTURE.pptx
DBMS ARCHITECTURE.pptxDBMS ARCHITECTURE.pptx
DBMS ARCHITECTURE.pptx
Anusha sivakumar
 
Database user and administrator.pptx
Database user and administrator.pptxDatabase user and administrator.pptx
Database user and administrator.pptx
Anusha sivakumar
 
CSS
CSSCSS
Greedy method
Greedy methodGreedy method
Greedy method
Anusha sivakumar
 
Heap sort
Heap sortHeap sort
Heap sort
Anusha sivakumar
 

More from Anusha sivakumar (10)

deadline.pptx
deadline.pptxdeadline.pptx
deadline.pptx
 
Evolution of Computers ppt.pptx
Evolution of Computers ppt.pptxEvolution of Computers ppt.pptx
Evolution of Computers ppt.pptx
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
PURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptxPURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptx
 
fundamental relation algebra.pptx
fundamental relation algebra.pptxfundamental relation algebra.pptx
fundamental relation algebra.pptx
 
DBMS ARCHITECTURE.pptx
DBMS ARCHITECTURE.pptxDBMS ARCHITECTURE.pptx
DBMS ARCHITECTURE.pptx
 
Database user and administrator.pptx
Database user and administrator.pptxDatabase user and administrator.pptx
Database user and administrator.pptx
 
CSS
CSSCSS
CSS
 
Greedy method
Greedy methodGreedy method
Greedy method
 
Heap sort
Heap sortHeap sort
Heap sort
 

Recently uploaded

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

NESTED SUBQUERY.pptx

  • 2. PREPARED BY Ms.R.Ragavi -III-B.Sc - Information Technology UNDER THE GUIDANCE OF Mrs.P.Anusha M.Sc(IT).,M.Phil.,D.P.T.T.,(Ph.D)., Assistant professor, Department of Information Technology, Bon secours college for women, Thanjavur.
  • 3. DEFINE NESTED SUBQUERY • A Subquery or inner query or a Nested query is a query within another SQL query and embedded within the WHERE clause. • A Common use of subqueries is to perform test for set membership, make set comparisons, and determine set cardinality by nesting of subqueries in the WHERE clause.
  • 4. USES • A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved. • Subquery can be used with the SELECT , INSERT, UPDATE , and DELETE statements along with the operators like =,<,>,>=,<=, IN BETWEEN etc. • Sub queries must be enclosed within parentheses.
  • 5. • A subquery can have only one column in the SELECT clause, unless multiple columns are in the main query for the sub query to compare its selected columns. • An ORDER BY COMMAND cannot to used in a subquery. • SQL provides a mechanism for nesting subqueries.
  • 6. CUSTOMER ID NAME AGE ADDRESS SALARY 001 ANITHA 30 CHIDAMBARAM 20,000 002 SIVAKAMI 25 KUMBAKONAM 24,000 003 ALAMELU 26 NEYVELI 26,000 004 GEETHA 45 THANJAVUR 38,000 005 RANI 35 TRICHY 20,000 006 MALATHI 36 BANGALORE 007 GOPI 29 KERALA
  • 7. SYNTAX • Select column name from table name where column name operator(select column name from table name where);
  • 8. EXAMPLE Select * from customers where customer_id IN (select customers_id from customers where salary >=25000; Customer _id Name Age Address Salary 003 Alamelu 26 Neyveli 26000 004 Geetha 45 Thanjavur 38000