0% found this document useful (0 votes)
9 views12 pages

Sub Query

This document provides an in-depth exploration of sub queries in SQL, defining their purpose as nested queries that enhance data retrieval capabilities. It discusses the performance considerations, particularly the impact of correlated sub queries, and compares them with non-correlated sub queries. The conclusion emphasizes the importance of understanding these concepts for efficient query writing and data management.

Uploaded by

harshitkumbhkar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Sub Query

This document provides an in-depth exploration of sub queries in SQL, defining their purpose as nested queries that enhance data retrieval capabilities. It discusses the performance considerations, particularly the impact of correlated sub queries, and compares them with non-correlated sub queries. The conclusion emphasizes the importance of understanding these concepts for efficient query writing and data management.

Uploaded by

harshitkumbhkar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Sub Query by

Harshit Kumbhkar
An in-depth look at sub queries and their functionalities in SQL.
Introduction
This presentation explores sub queries, their definitions,
purposes, and practical use cases in SQL databases.
01
Sub Query
Definition and
Purpose
A sub query is a query nested inside another query, often used to perform
operations such as filtering, selecting, or calculating values based on the
results of the outer query. They enhance the functionality and complexity
of SQL statements, allowing for more dynamic data retrieval.
Use Cases in SQL
Sub queries serve various purposes in SQL, including filtering
results using the results of another query, performing calculations
within queries, and creating more readable and maintainable SQL
statements by breaking complex queries into simpler components.
Performance
Consideratio
ns
When using sub queries, performance can be
impacted, especially with correlated sub queries
that reference fields from the outer query. This
can lead to multiple executions of the inner
query, making them slower. It's often more
efficient to use joins or to rewrite queries for
optimal performance.
02
Correlated Sub Query
Definition
and Purpose
A correlated sub query is a type of sub query
that references columns from the outer query.
Each time the outer query is processed, the
inner query is executed. This allows for
dynamic, context-sensitive results, making them
useful for comparisons or computations that
depend on the outer query's context.
Examples in SQL
An example of a correlated sub query is finding employees whose salaries
are above the average for their department. The inner query calculates
the average salary for the department that the outer query is currently
processing, allowing tailored comparisons based on each employee's
department.
Comparison with Non-
Correlated Sub Queries
Non-correlated sub queries can execute independently of the outer query
and return a single result set, while correlated sub queries depend on the
outer query's current row context. Generally, non-correlated sub queries
perform better in terms of speed and efficiency than correlated ones due
to fewer executions.
Conclusions
Sub queries and correlated sub queries are powerful tools in SQL.
Understanding their definitions, purposes, and performance
considerations allows for more efficient and effective query
writing, helping to better manage complex data retrieval tasks.
Thank you!
Do you have any questions?

CREDITS: This presentation template was


created by Slidesgo, and includes icons by
Flaticon, and infographics & images by
Freepik
+ 9 1 6 2 0 4 2 1 8 3 8

You might also like