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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / 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

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

Answer / 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

More SQL PLSQL Interview Questions

What do you understand by pl/sql packages?

0 Answers  


How to run sql commands in sql*plus?

0 Answers  


What is the use of desc in sql?

0 Answers  


which will default fire first  statement level trigger or row level trigger

2 Answers   Cap Gemini, Data Vision,


How exception handling is done in advance pl/sql?

0 Answers  






How do I copy a table in sql?

0 Answers  


Why is pl sql needed?

0 Answers  


Can a table contain multiple primary key’s?

0 Answers  


What is the primary key?

0 Answers  


What are sql functions? Describe in brief different types of sql functions?

0 Answers  


Is it possible to include an insert statement on the same table to which the trigger is assigned?

0 Answers  


Write a query to find the name of employees those who have joined on Monday.(based on column hire_date)

15 Answers   Satyam,


Categories