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


Please Help Members By Posting Answers For Below Questions

How do you modify a column in sql?

732


What is difference between function and trigger?

721


What is a temporal data type?

775


Can we use ddl statements in stored procedure?

885


what is a relationship and what are they? : Sql dba

752






what is view? : Sql dba

730


give the syntax of grant and revoke commands? : Sql dba

805


What is the difference between microsoft sql and mysql?

710


What is transaction control language (tcl)?

849


How to read xml file in oracle pl sql?

693


What is the difference between clustered and non-clustered indexes?

802


What are the indexing methods?

765


How does sql store data?

663


What are conditional predicates?

788


What are the advantages of pl sql?

835