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 dba in sql? : SQL DBA
How to avoid using cursors?
What is the best sql course?
What is a native sql query?
How do I edit a trigger in sql developer?
What are the sql commands?
what is self join and what is the requirement of self join? : Sql dba
Is microsoft sql free?
what are different types of collation sensitivity? : Sql dba
What is scalar function in sql?
What is left join in postgresql?
What is the difference between sql and mysql?
What is indexing in sql and its types?
What are the ddl commands?
what happens if you no create privilege in a database? : Sql dba