SlideShare a Scribd company logo
SQL SUBQUERY
S.M. TOWHIDUL ISLAM
181-35-2435
E
WHAT IS A SUBQUERY?
 A subquery is a SELECT statement embedded in a clause of another SQL statement (SELECT, INSERT,
UPDATE, DELETE).
 SQL subquery is usually added in the WHERE Clause of the SQL statement.
SELECT . . .
FROM . . .
WHERE . . .
(SELECT . . .
FROM . . .
WHERE . . .)
Main
Query
Subquery
SUBQUERY
 Subquery or Inner query or Nested query.
 An alternate way of returning data from multiple tables.
 Subqueries can be used with the following SQL statements along with the comparison operators like =,
<, >, >=, <= etc.
 Subqueries can also be used inside the WHERE or HAVING clause.
SELECT select_list
From table
WHERE OOP operator SELECT select_list
From table
SUB-QUERY SYNTAX
The subquery (inner query) executes once
before the main query.
 The result of the subquery is used by the
main query (outer query).
TYPES OF SUBQUERIES
TYPES OF SUBQUERIES
 Single-row subqueries: Queries that return only one row from the inner SELECT statement.
TYPES OF SUBQUERIES
 Multiple-row subqueries: Queries that return more than one row from the inner SELECT statement.
THANK YOU

More Related Content

PDF
Sub query_SQL
 
PPTX
Sql subquery
PDF
Oracle SQL Part 2
PPTX
Oracle apps financial online training
PPTX
Oracle SQL - Grants, filters, groups and more
PPTX
MySQL index optimization techniques
PPTX
Oracle SQL - Select Part -1 let's write some queries!
PPTX
How mysql choose the execution plan
Sub query_SQL
 
Sql subquery
Oracle SQL Part 2
Oracle apps financial online training
Oracle SQL - Grants, filters, groups and more
MySQL index optimization techniques
Oracle SQL - Select Part -1 let's write some queries!
How mysql choose the execution plan

What's hot (18)

PPTX
Union based sql injection by Urdu Tutorials Point
PPT
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
PPT
e computer notes - Other database objects
PDF
7. Using Sub Queries
PPT
Retrieving data using the sql select statement
PPT
SQL select statement and functions
PDF
Oracle SQL Part 3
PDF
Ch05
DOC
Module 3
PPT
Les01 (retrieving data using the sql select statement)
PDF
Ch04
PPTX
MYSQL single rowfunc-multirowfunc-groupby-having
PDF
MySQL Query And Index Tuning
PDF
Sql operators comparision & logical operators
PPT
e computer notes - Advanced subqueries
PPTX
Sql modifying data - MYSQL part I
PPT
Union based sql injection by Urdu Tutorials Point
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
e computer notes - Other database objects
7. Using Sub Queries
Retrieving data using the sql select statement
SQL select statement and functions
Oracle SQL Part 3
Ch05
Module 3
Les01 (retrieving data using the sql select statement)
Ch04
MYSQL single rowfunc-multirowfunc-groupby-having
MySQL Query And Index Tuning
Sql operators comparision & logical operators
e computer notes - Advanced subqueries
Sql modifying data - MYSQL part I
Ad

Similar to Sub-Queries (20)

PDF
Sql subquery
PPTX
Sub query example with advantage and disadvantages
PDF
SQL Benefits
PPTX
Data base management system full details
PPTX
SQL Joins & Sub Queries class number 697
PPTX
SQL Tutorial for Beginners
PPTX
Lesson-02 (1).pptx
PPTX
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
PPT
SQL subquery
PPTX
SQL Fundamentals
PPTX
NESTED SUBQUERY.pptx
PPTX
Database management system Lecture 6.pptx
PPTX
2..basic queries.pptx
DOCX
PPTX
MULTIPLE TABLES
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
PPTX
XII_IP_PPT[2].pptxhggggggggggggggggggggggggggggggggdj
PPTX
SQL COMMANDS WITH EXAMPLES.pptx
PPTX
DBMS and SQL(structured query language) .pptx
PDF
sql notes Provideby AGN HUB Tech & It Solutions
Sql subquery
Sub query example with advantage and disadvantages
SQL Benefits
Data base management system full details
SQL Joins & Sub Queries class number 697
SQL Tutorial for Beginners
Lesson-02 (1).pptx
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
SQL subquery
SQL Fundamentals
NESTED SUBQUERY.pptx
Database management system Lecture 6.pptx
2..basic queries.pptx
MULTIPLE TABLES
Database Management - Lecture 2 - SQL select, insert, update and delete
XII_IP_PPT[2].pptxhggggggggggggggggggggggggggggggggdj
SQL COMMANDS WITH EXAMPLES.pptx
DBMS and SQL(structured query language) .pptx
sql notes Provideby AGN HUB Tech & It Solutions
Ad

More from S.M. Towhidul Islam (9)

PPTX
Introduction to information security
PPTX
Enterprise resource planning(ERP)
PDF
Endpoint security
PDF
Recent cyber Attacks
PDF
Cryptography
PPTX
Attack types
PPTX
Internal audit
PPTX
Sensitive data
Introduction to information security
Enterprise resource planning(ERP)
Endpoint security
Recent cyber Attacks
Cryptography
Attack types
Internal audit
Sensitive data

Recently uploaded (20)

PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Trump Administration's workforce development strategy
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Trump Administration's workforce development strategy
O5-L3 Freight Transport Ops (International) V1.pdf
human mycosis Human fungal infections are called human mycosis..pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
GDM (1) (1).pptx small presentation for students
Weekly quiz Compilation Jan -July 25.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Yogi Goddess Pres Conference Studio Updates
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx

Sub-Queries

  • 1. SQL SUBQUERY S.M. TOWHIDUL ISLAM 181-35-2435 E
  • 2. WHAT IS A SUBQUERY?  A subquery is a SELECT statement embedded in a clause of another SQL statement (SELECT, INSERT, UPDATE, DELETE).  SQL subquery is usually added in the WHERE Clause of the SQL statement. SELECT . . . FROM . . . WHERE . . . (SELECT . . . FROM . . . WHERE . . .) Main Query Subquery
  • 3. SUBQUERY  Subquery or Inner query or Nested query.  An alternate way of returning data from multiple tables.  Subqueries can be used with the following SQL statements along with the comparison operators like =, <, >, >=, <= etc.  Subqueries can also be used inside the WHERE or HAVING clause. SELECT select_list From table WHERE OOP operator SELECT select_list From table
  • 4. SUB-QUERY SYNTAX The subquery (inner query) executes once before the main query.  The result of the subquery is used by the main query (outer query).
  • 6. TYPES OF SUBQUERIES  Single-row subqueries: Queries that return only one row from the inner SELECT statement.
  • 7. TYPES OF SUBQUERIES  Multiple-row subqueries: Queries that return more than one row from the inner SELECT statement.