we write CTE sql like below one
WITH yourCTE AS
(
SELECT .... FROM :... WHERE.....
) SELECT * FROM yourCTE
what would be advantage to put sql in with block. i think that if we put complicated sql in with block then we just can write sql like SELECT * FROM yourCTE
. as if i am accessing view.
what is added advantage of using CTE in terms of performance. please discuss. thanks
1. Using CTE improves the readability and makes maintenance of complex queries easy. 2. The query can be divided into separate, simple, logical building blocks which can be then used to build more complex CTEs until final result set is generated.
CTEs, like database views and derived tables, enable users to more easily write and maintain complex queries via increased readability and simplification. This reduction in complexity is achieved by deconstructing ordinarily complex queries into simple blocks to be used, and reused if necessary, in rewriting the query.
Advantage of Using CTE CTE can be more readable: Another advantage of CTE is CTE are more readable than Subqueries. Since CTE can be reusable, you can write less code using CTE than using subquery. Also, people tend to follow the logic and ideas easier in sequence than in a nested fashion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With