General
SUBQUERIES and CTEs
0 views

SUBQUERIES
Subquery is a query inside a query and is used when one statement needs a result from another. It is usually inside a clause like 'where' :
'from'
or 'select'.
CTE
A CTE(Common Table Expression) is a temporary named result set that one can reference within single query to reuse in the next query.
Advantages of CTE
CTEs tend to be preferred for readability and structuring complex structure.
A thing with CTEs is it is reusable in that you can reuse the definition without rewriting it.
Difference between subquery and CTE
CTEs support recursion while subqueries do not.
Subqueries can be correlated while CTE cannot.
conclusion
When writing and reading SQL the style I prefer and will pick is usually CTEs as they are easier to read and follow through. Also the fact that it takes less rework when going back to look or want to retrieve information.
Read original: https://dev.to/elizabeth_njoroge_7c850b9/subqueries-and-ctes-2e5n
Related posts
Adventurer returns home to Hull after 28-year walk from South America
0Hacker News New
Vending machine has terms and conditions you must accept before using [video]
0Hacker News New
Tomorrow Corporation Tech Demo [video]
0Hacker News New
Does Social Status Run in Families?
0Hacker News New
Show HN: Svoxx – A multilingual freelance marketplace with social features
0Hacker News New
433MHz TUI scanner: using a FT232H connected to a CC1101
0Hacker News New