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
What is the order of sql select?
What is the difference between pl and sql?
what is query cache in mysql? : Sql dba
how can we find the number of rows in a table using mysql? : Sql dba
what are the 'mysql' command line options? : Sql dba
explain the difference between delete , truncate and drop commands? : Sql dba
Show the cursor attributes of pl/sql.
list out some tools through which we can draw e-r diagrams for mysql. : Sql dba
Is postgresql a nosql database?
Can we use joins in subquery?
What is relationship? How many types of relationship are there?
What is a delimiter in sas?
Is sql better than excel?
What are the set operators in sql?
How can you get sql*loader to commit only at the end of the load file? : aql loader