0% found this document useful (0 votes)
22 views7 pages

CTE Vs Subquery

Subquery

Uploaded by

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

CTE Vs Subquery

Subquery

Uploaded by

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

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

You might also like