SlideShare a Scribd company logo
1 of 9
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 (20)

Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
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
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
DBMS Keys
DBMS KeysDBMS Keys
DBMS Keys
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Join
JoinJoin
Join
 
Er model ppt
Er model pptEr model ppt
Er model ppt
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Relational model
Relational modelRelational model
Relational model
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Sql commands
Sql commandsSql commands
Sql commands
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 

Similar to Nested queries in database

Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statementsArun Nair
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxuzmasulthana3
 
ADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptxADV Powepoint 6 Lec.pptx
ADV Powepoint 6 Lec.pptxArjayBalberan1
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
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, SubQueryAbhishek590097
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd sessionMedhat Dawoud
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Techglyphs
 
Assignment 3
Assignment 3Assignment 3
Assignment 3SneaK3
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptxssuserb8d5cb
 

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
 
Sql join
Sql  joinSql  join
Sql join
 
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
 
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.pptxSatya P. Joshi
 
Training methods in human resource managment
Training methods in human resource managmentTraining methods in human resource managment
Training methods in human resource managmentSatya P. Joshi
 
Selection tests in human resource management
Selection tests in human resource managementSelection tests in human resource management
Selection tests in human resource managementSatya 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 managmenetSatya P. Joshi
 
Motivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theoryMotivation, achievement theory, goal setting theory
Motivation, achievement theory, goal setting theorySatya 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 managerSatya P. Joshi
 
Human Resource Planning
Human Resource PlanningHuman Resource Planning
Human Resource PlanningSatya 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 RelationSatya 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 serviceSatya 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 MultimediaSatya P. Joshi
 
Introduction to human resource management
Introduction to human resource managementIntroduction to human resource management
Introduction to human resource managementSatya 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 SystemSatya P. Joshi
 
Designing the supply chain network
Designing the supply chain networkDesigning the supply chain network
Designing the supply chain networkSatya 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 RelationSatya 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 HRMSatya 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 logicSatya 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 networkSatya 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 computingSatya 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 serverSatya 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 serverSatya 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

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 

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; )