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
Can we create view in stored procedure?
How do I use google cloud in sql?
What is the mutating table and constraining table?
Can a key be both primary and foreign?
What does desc stand for?
What is update query?
In what condition is it good to disable a trigger?
How will you distinguish a global variable with a local variable in pl/sql?
What is difference between group by and partition by?
Which certification is best for sql?
Why do we use function in pl sql?
What is the non-clustered index in sql?
Which tcp/ip port does sql server run on? How can it be changed? : Sql dba
What are the limitations of sql express?
What is the use of primary key?