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 does postgresql compare to "nosql"?
What is t-sql? : Transact sql
write an sql query to get third maximum salary of an employee from a table named employee_table. : Sql dba
Explain the difference between drop and truncate commands in sql?
What is rank dense_rank and partition in sql?
how is exception handling handled in mysql? : Sql dba
What is the left table in sql?
What is nvarchar max in sql?
What are the types of views in sql?
How do we accept inputs from user during runtime?
what is the difference between inner and outer join? Explain with example. : Sql dba
How many types of tables are there?
Do triggers have restrictions on the usage of large datatypes, such as long and long raw?
What is a common use of group by in sql?
What are all the different normalizations?