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


Please Help Members By Posting Answers For Below Questions

What is nvl?

790


What are the uses of merge?

896


what happens if null values are involved in expressions? : Sql dba

738


Differences between Oracle 9i and 10g (Probably in terms of SQL and PL/SQL)?

3313


how to get help information from the server? : Sql dba

679






what is sql? : Sql dba

743


What is sql profiler in oracle?

759


What is primary key in db?

712


What is #table in sql?

706


How many unique keys can a table have?

740


what are local and global variables and their differences? : Sql dba

718


How many disk partitions should I have?

719


How to download oracle sql developer?

856


What is an implicit commit?

762


What are the 3 modes of parameter?

866