What is a CTE (Common Table Expression), and how is it different from a subquery?
Answer Posted / glibwaresoftsolutions
• 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
How do you modify a column in sql?
What is difference between function and trigger?
What is a temporal data type?
Can we use ddl statements in stored procedure?
what is a relationship and what are they? : Sql dba
what is view? : Sql dba
give the syntax of grant and revoke commands? : Sql dba
What is the difference between microsoft sql and mysql?
What is transaction control language (tcl)?
How to read xml file in oracle pl sql?
What is the difference between clustered and non-clustered indexes?
What are the indexing methods?
How does sql store data?
What are conditional predicates?
What are the advantages of pl sql?