SlideShare a Scribd company logo
1. Set Membership
2. Set Comparison
3. Test for Empty Relation
4. Test for The Absence of
Duplicate Tuples
Presented By
Tutsmaster.org
 A Sub query or Inner query or Nested query is
a query within another SQL query and
embedded within the WHERE clause.
 A sub query is used to return data that will be
used in the main query as a condition to
further restrict the data to be retrieved.
 Subqueries can be used with the SELECT,
INSERT, UPDATE, and DELETE statements
along with the operators like =, <, >, >=,
<=, IN, BETWEEN etc.
 Subqueries 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 subquery
to compare its selected columns.
 An ORDER BY cannot be used in a subquery, although the main
query can use an ORDER BY. The GROUP BY can be used to
perform the same function as the ORDER BY in a subquery.
 Subqueries that return more than one row can only be used with
multiple value operators, such as the IN operator.
 The SELECT list cannot include any references to values that
evaluate to a BLOB (Binary Large Object), ARRAY, CLOB((Character
Large Object), or NCLOB.
 A subquery cannot be immediately enclosed in a set function.
 The BETWEEN operator cannot be used with a subquery; however,
the BETWEEN operator can be used within the subquery.
 It is used to check if value of expression is
matching a set of values produced by a sub
query. For sub query set membership
condition, In Keyword is used.
Example
SELECT NAME FROM EMPLOYEES
WHERE EMPLOYEE IN (
SELECT COMPANY FROM COMPANIES
WHERE AVG_SALES > TOTAL_SALES
 It is used to compare value of expression in
marching a set produced by a sub query. For
sub query set comparison, operation (> and
<) are used
 Example
SELECT NAME FROM EMPLOYEES
WHERE EMPLOYEE IN
(SELECT COMPANY FROM COMPANIES
WHERE AVG_SALES > TOTAL_SALES)=
(SELECT COMPANY FROM COMPANIES
WHERE BRANCH=‘TEXAS’ )
 SQL includes a feature for testing whether a
sub query has any tuples in its result. EXISTS
uses a sub query as a condition, where the
condition is True if the sub query returns any
rows and False if the sub query does not
return any rows; this is a non intuitive feature
with few unique uses.
 EXIST- This operator evaluate to true if the
resulting set is not empty.
 NOT EXIST – This operator evaluated to true if
the resulting set is empty.
TEST EMPTY RELATIONS
SELECT BRANCH
FROM COMPANIES
WHERE EXISTS (
SELECT CAPITAL FROM COMPANY> 100000)
EXCEPT(
SELECT NAME FROM COMPANY=‘ENTERPRISE’
)
 The unique construct returns true if the
argument subquery contains no duplicate tuples.
 SQL includes a feature for testing whether a sub
query has any duplicate tuples in its result The
UNIQUE construct return the value true if the
argument sub query contains no duplicate tuples.
Using the UNIQUE construct, we can write the
query ‘Find all customer
 Example
SELECT NAME FROM EMPLOYEE
WHERE UNIQUE(
SELECT SALARY FROM EMPLOYE = 100000;
)

More Related Content

What's hot

Dbms keys
Dbms keysDbms keys
Dbms keys
RUpaliLohar
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
Shishir Aryal
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
SQL Views
SQL ViewsSQL Views
SQL Views
Aaron Buma
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
VENNILAV6
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
Sql joins
Sql joinsSql joins
Sql joins
Gaurav Dhanwant
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
Archit Saxena
 
Normal forms
Normal formsNormal forms
Normal forms
Samuel Igbanogu
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
Saranya Natarajan
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
Anusha sivakumar
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 

What's hot (20)

Dbms keys
Dbms keysDbms keys
Dbms keys
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
DBMS Keys
DBMS KeysDBMS Keys
DBMS Keys
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Sql joins
Sql joinsSql joins
Sql joins
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Normal forms
Normal formsNormal forms
Normal forms
 
Sql join
Sql  joinSql  join
Sql join
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 

Similar to Nested queries in database

Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
bixxman
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statementsArun Nair
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
Gurpreet singh
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
Join sql
Join sqlJoin sql
Join sql
Vikas Gupta
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
uzmasulthana3
 
ADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptxADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptx
ArjayBalberan1
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
ASHABOOPATHY
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
Evelyn Oluchukwu
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
Vikas Gupta
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
Abhishek590097
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd session
Medhat Dawoud
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2
Techglyphs
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
SneaK3
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
ssuserb8d5cb
 
Merging data (1)
Merging data (1)Merging data (1)
Merging data (1)
Ris Fernandez
 

Similar to Nested queries in database (20)

Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statements
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Join sql
Join sqlJoin sql
Join sql
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
 
Les18
Les18Les18
Les18
 
ADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptxADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptx
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
 
Les06
Les06Les06
Les06
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd session
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
 
ADVANCED MODELLING.pptx
ADVANCED MODELLING.pptxADVANCED MODELLING.pptx
ADVANCED MODELLING.pptx
 
Merging data (1)
Merging data (1)Merging data (1)
Merging data (1)
 

More from Satya P. Joshi

Intergroup Conflict Management.pptx
Intergroup Conflict Management.pptxIntergroup Conflict Management.pptx
Intergroup Conflict Management.pptx
Satya P. Joshi
 
Training methods in human resource managment
Training methods in human resource managmentTraining methods in human resource managment
Training methods in human resource managment
Satya P. Joshi
 
Selection tests in human resource management
Selection tests in human resource managementSelection tests in human resource management
Selection tests in human resource management
Satya P. Joshi
 
Interview and it’s types - human resource managmenet
Interview and it’s types - human resource managmenetInterview and it’s types - human resource managmenet
Interview and it’s types - human resource managmenet
Satya P. Joshi
 
Motivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theoryMotivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theory
Satya P. Joshi
 
Characteristics, objectives &amp; challenges of human resource manager
Characteristics, objectives &amp; challenges of human resource managerCharacteristics, objectives &amp; challenges of human resource manager
Characteristics, objectives &amp; challenges of human resource manager
Satya P. Joshi
 
Human Resource Planning
Human Resource PlanningHuman Resource Planning
Human Resource Planning
Satya P. Joshi
 
Technology and work design in Organizational Relation
Technology and work design in Organizational RelationTechnology and work design in Organizational Relation
Technology and work design in Organizational Relation
Satya P. Joshi
 
Techniques of achieving google quality of service
Techniques of achieving google quality of serviceTechniques of achieving google quality of service
Techniques of achieving google quality of service
Satya P. Joshi
 
Overview of digital communication in HSN and Multimedia
Overview of digital communication in HSN and MultimediaOverview of digital communication in HSN and Multimedia
Overview of digital communication in HSN and Multimedia
Satya P. Joshi
 
Introduction to human resource management
Introduction to human resource managementIntroduction to human resource management
Introduction to human resource management
Satya P. Joshi
 
Security and control in Management Information System
Security and control in Management Information SystemSecurity and control in Management Information System
Security and control in Management Information System
Satya P. Joshi
 
Designing the supply chain network
Designing the supply chain networkDesigning the supply chain network
Designing the supply chain network
Satya P. Joshi
 
Introduction to Organizational Behavior and Organizational Relation
Introduction to Organizational Behavior and Organizational RelationIntroduction to Organizational Behavior and Organizational Relation
Introduction to Organizational Behavior and Organizational Relation
Satya P. Joshi
 
Selection tests and Reliability and Validity in HRM
Selection tests and Reliability and Validity in HRMSelection tests and Reliability and Validity in HRM
Selection tests and Reliability and Validity in HRM
Satya P. Joshi
 
Analog and digital signal system : digital logic
Analog and digital signal system : digital logicAnalog and digital signal system : digital logic
Analog and digital signal system : digital logic
Satya P. Joshi
 
Transmission media on Client server and high speed network
Transmission media on Client server and high speed networkTransmission media on Client server and high speed network
Transmission media on Client server and high speed network
Satya P. Joshi
 
Remote procedure call on client server computing
Remote procedure call on client server computingRemote procedure call on client server computing
Remote procedure call on client server computing
Satya P. Joshi
 
Physical and logical topologies in computer network and client server
Physical  and logical topologies in computer network and client serverPhysical  and logical topologies in computer network and client server
Physical and logical topologies in computer network and client server
Satya P. Joshi
 
Performance tuning and optimization on client server
Performance tuning and optimization on client serverPerformance tuning and optimization on client server
Performance tuning and optimization on client server
Satya P. Joshi
 

More from Satya P. Joshi (20)

Intergroup Conflict Management.pptx
Intergroup Conflict Management.pptxIntergroup Conflict Management.pptx
Intergroup Conflict Management.pptx
 
Training methods in human resource managment
Training methods in human resource managmentTraining methods in human resource managment
Training methods in human resource managment
 
Selection tests in human resource management
Selection tests in human resource managementSelection tests in human resource management
Selection tests in human resource management
 
Interview and it’s types - human resource managmenet
Interview and it’s types - human resource managmenetInterview and it’s types - human resource managmenet
Interview and it’s types - human resource managmenet
 
Motivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theoryMotivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theory
 
Characteristics, objectives &amp; challenges of human resource manager
Characteristics, objectives &amp; challenges of human resource managerCharacteristics, objectives &amp; challenges of human resource manager
Characteristics, objectives &amp; challenges of human resource manager
 
Human Resource Planning
Human Resource PlanningHuman Resource Planning
Human Resource Planning
 
Technology and work design in Organizational Relation
Technology and work design in Organizational RelationTechnology and work design in Organizational Relation
Technology and work design in Organizational Relation
 
Techniques of achieving google quality of service
Techniques of achieving google quality of serviceTechniques of achieving google quality of service
Techniques of achieving google quality of service
 
Overview of digital communication in HSN and Multimedia
Overview of digital communication in HSN and MultimediaOverview of digital communication in HSN and Multimedia
Overview of digital communication in HSN and Multimedia
 
Introduction to human resource management
Introduction to human resource managementIntroduction to human resource management
Introduction to human resource management
 
Security and control in Management Information System
Security and control in Management Information SystemSecurity and control in Management Information System
Security and control in Management Information System
 
Designing the supply chain network
Designing the supply chain networkDesigning the supply chain network
Designing the supply chain network
 
Introduction to Organizational Behavior and Organizational Relation
Introduction to Organizational Behavior and Organizational RelationIntroduction to Organizational Behavior and Organizational Relation
Introduction to Organizational Behavior and Organizational Relation
 
Selection tests and Reliability and Validity in HRM
Selection tests and Reliability and Validity in HRMSelection tests and Reliability and Validity in HRM
Selection tests and Reliability and Validity in HRM
 
Analog and digital signal system : digital logic
Analog and digital signal system : digital logicAnalog and digital signal system : digital logic
Analog and digital signal system : digital logic
 
Transmission media on Client server and high speed network
Transmission media on Client server and high speed networkTransmission media on Client server and high speed network
Transmission media on Client server and high speed network
 
Remote procedure call on client server computing
Remote procedure call on client server computingRemote procedure call on client server computing
Remote procedure call on client server computing
 
Physical and logical topologies in computer network and client server
Physical  and logical topologies in computer network and client serverPhysical  and logical topologies in computer network and client server
Physical and logical topologies in computer network and client server
 
Performance tuning and optimization on client server
Performance tuning and optimization on client serverPerformance tuning and optimization on client server
Performance tuning and optimization on client server
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

Nested queries in database

  • 1. 1. Set Membership 2. Set Comparison 3. Test for Empty Relation 4. Test for The Absence of Duplicate Tuples Presented By Tutsmaster.org
  • 2.  A Sub query or Inner query or Nested query is a query within another SQL query and embedded within the WHERE clause.  A sub query is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.  Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN etc.
  • 3.  Subqueries 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 subquery to compare its selected columns.  An ORDER BY cannot be used in a subquery, although the main query can use an ORDER BY. The GROUP BY can be used to perform the same function as the ORDER BY in a subquery.  Subqueries that return more than one row can only be used with multiple value operators, such as the IN operator.  The SELECT list cannot include any references to values that evaluate to a BLOB (Binary Large Object), ARRAY, CLOB((Character Large Object), or NCLOB.  A subquery cannot be immediately enclosed in a set function.  The BETWEEN operator cannot be used with a subquery; however, the BETWEEN operator can be used within the subquery.
  • 4.
  • 5.  It is used to check if value of expression is matching a set of values produced by a sub query. For sub query set membership condition, In Keyword is used. Example SELECT NAME FROM EMPLOYEES WHERE EMPLOYEE IN ( SELECT COMPANY FROM COMPANIES WHERE AVG_SALES > TOTAL_SALES
  • 6.  It is used to compare value of expression in marching a set produced by a sub query. For sub query set comparison, operation (> and <) are used  Example SELECT NAME FROM EMPLOYEES WHERE EMPLOYEE IN (SELECT COMPANY FROM COMPANIES WHERE AVG_SALES > TOTAL_SALES)= (SELECT COMPANY FROM COMPANIES WHERE BRANCH=‘TEXAS’ )
  • 7.  SQL includes a feature for testing whether a sub query has any tuples in its result. EXISTS uses a sub query as a condition, where the condition is True if the sub query returns any rows and False if the sub query does not return any rows; this is a non intuitive feature with few unique uses.  EXIST- This operator evaluate to true if the resulting set is not empty.  NOT EXIST – This operator evaluated to true if the resulting set is empty. TEST EMPTY RELATIONS
  • 8. SELECT BRANCH FROM COMPANIES WHERE EXISTS ( SELECT CAPITAL FROM COMPANY> 100000) EXCEPT( SELECT NAME FROM COMPANY=‘ENTERPRISE’ )
  • 9.  The unique construct returns true if the argument subquery contains no duplicate tuples.  SQL includes a feature for testing whether a sub query has any duplicate tuples in its result The UNIQUE construct return the value true if the argument sub query contains no duplicate tuples. Using the UNIQUE construct, we can write the query ‘Find all customer  Example SELECT NAME FROM EMPLOYEE WHERE UNIQUE( SELECT SALARY FROM EMPLOYE = 100000; )