What is a CTE (Common Table Expression), and how is it different from a subquery?
Answer Posted / nashiinformaticssolutions
• 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 the difference between a primary key and a clustered index?
What is left inner join in sql?
How do I filter in sql profiler?
Why procedure is used in sql?
What is mutating sql table?
What is sql resultset?
What is trigger price?
What is trigger in pl sql with examples?
how to enter characters as hex numbers? : Sql dba
How does a covering index work?
what are the authentication modes in sql server? How can it be changed? : Sql dba
what are the type of locks ? : Sql dba
Explain what is table in a database?
What pl/sql package consists of?
how to fetch alternate records from a table? : Sql dba