About 2,840,000 results
Open links in new tab
  1. sql - When to use Common Table Expression (CTE) - Stack Overflow

    Jan 5, 2017 · 31 One of the scenarios I found useful to use CTE is when you want to get DISTINCT rows of data based on one or more columns but return all columns in the table.

  2. sql - Is there a performance difference between CTE , Sub-Query ...

    Jun 23, 2012 · In this excellent SO question, differences between CTE and sub-queries were discussed. I would like to specifically ask: In what circumstance is each of the following more efficient/faster? …

  3. sql - Referencing a CTE in a where clause - Stack Overflow

    Mar 7, 2025 · I'm trying to use a CTE at the top of my query to be referenced in WHERE clause in a separate CTE further down. For Example: with ref as ( null email, ' ("720884","70540"...

  4. sql server - Which are more performant, CTE or temporary tables ...

    Mar 27, 2009 · SQL Server query engine parse the CTE code as part of the query text and build an execution plan according. The idea that CTE is inline is the big advantage of using CTE, since it …

  5. SQL Server CTE and recursion example - Stack Overflow

    I never use CTE with recursion. I was just reading an article on it. This article shows employee info with the help of Sql server CTE and recursion. It is basically showing employees and their mana...

  6. SQL - Use a reference of a CTE to another CTE - Stack Overflow

    The CTE can be used in a from clause at any level of nesting within other subqueries. The CTEs -- as with everything in SQL -- need to be defined before they are used.

  7. sql server - Keeping it simple and how to do multiple CTE in a query ...

    Example C, "Using multiple CTE definitions in a single query," calls this out explicitly. Sadly, this example is not provided in the documentation for SQL 2008 and older (i.e., the example wasn't …

  8. sql - What are the advantages/disadvantages of using a CTE? - Stack ...

    Sep 10, 2008 · A CTE is not much more than syntactic sugar. It enhances the readability and allows to avoid repetition. Just think of it as a placeholder for the actual statement specified in the WITH() …

  9. sql - Can you create nested WITH clauses for Common Table …

    While not strictly nested, you can use common table expressions to reuse previous queries in subsequent ones. To do this, the form of the statement you are looking for would be

  10. sql - How to remove duplicate rows using CTE? - Stack Overflow

    May 30, 2021 · How to remove duplicate rows using CTE? Asked 4 years, 7 months ago Modified 1 year, 9 months ago Viewed 16k times