What is a CTE (Common Table Expression), and how is it different from a subquery?
Answer Posted / hr@tgksolutions.com
• CTE: Temporary result set defined using WITH and reusable within the query. Improves readability for complex queries.
• Subquery: Nested query executed each time it is called. Example:
WITH SalesCTE AS (
SELECT employee_id, SUM(sales) AS total_sales
FROM sales
GROUP BY employee_id
)
SELECT * FROM SalesCTE WHERE total_sales > 5000;
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what is 'trigger' in sql? : Sql dba
What are the packages in pl sql?
what is collation? : Sql dba
What are types of exception?
What is java sql package?
What are all the common sql functions?
What is the use of stored procedures?
What are the advantages of normalization?
How can you maintain the integrity of your database on instances where deleting an element in a table result in the deletion of the element(s) within another table?
What are the usages of sql?
tell me about various levels of constraint. : Sql dba
How do I find duplicates in sql?
Why is sql*loader direct path so fast?
What are the disadvantages of file system?
Why do we need cursor in pl sql?