CTE &
SUBQUERY
IN SQL
@PRANEETA_GUPTA
SYNTAX
A subquery is a query embedded
inside another query.
A CTE is a named temporary
result set defined using the WITH
keyword
01
@PRANEETA_GUPTA
READABILITY
CTEs can make queries more
readable and easier to
understand, especially with
multiple levels of subqueries.
Naming a CTE helps clarify its
meaning and how it's used in the
main query.
02
@PRANEETA_GUPTA
REUSABILITY
CTEs can be referenced multiple
times within the same query.
Subqueries can only be used
once, making CTEs more flexible
if the same result set is needed in
various parts of the query.
03
@PRANEETA_GUPTA
PERFORMANCE
CTEs can be referenced multiple
times within the same query.
Subqueries can only be used
once, making CTEs more flexible
if the same result set is needed in
various parts of the query.
04
@PRANEETA_GUPTA
CONCLUSION
Both CTEs and subqueries are
valuable for defining temporary
result sets in SQL. The choice
between them depends on the
specific needs of the query and
the data's performance
characteristics.
05
FOLLOW ME FOR MORE
SUCH INSIGHTS
@PRANEETA_GUPTA