What is a CTE (Common Table Expression), and how is it different from a subquery?

Answer Posted / nashiinformaticssolutions

• 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

Why truncate is faster than delete?

798


Differentiate between % rowtype and type record.

923


What are the basic techniques of indexing?

782


How to install oracle sql developer?

774


What is a unique key and primary key and foreign key?

744






Can a table contain multiple primary key’s?

809


what does the t-sql command ident_incr does? : Transact sql

805


Is it possible to sort a column using a column alias?

818


What are all ddl commands?

744


How do I trace sql profiler?

708


How to connect a sql*plus session to an oracle server?

819


What is a Mapplet?

828


Which sorts rows in sql?

776


What is indexes?

756


How is use pl and sql?

738