{"id":974,"date":"2025-02-07T08:00:00","date_gmt":"2025-02-07T13:00:00","guid":{"rendered":"https:\/\/www.sqltabletalk.com\/?p=974"},"modified":"2025-02-07T10:59:47","modified_gmt":"2025-02-07T15:59:47","slug":"tsql-common-table-expressions-recursive-queries","status":"publish","type":"post","link":"https:\/\/www.sqltabletalk.com\/?p=974","title":{"rendered":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional <code>IF<\/code> statements, loops, <code>CASE<\/code> expressions, and covered essential concepts like error handling and transaction management. Now, we turn to <strong>Common Table Expressions (CTEs)<\/strong>\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.<\/p>\n<p>Although CTEs are often introduced as an alternative to subqueries and temporary tables, their real strength emerges when you leverage <em>recursive CTEs<\/em> to tackle hierarchical data structures. In this post, we\u2019ll define CTEs, compare them briefly to other approaches, and illustrate how recursive queries work in practice.<\/p>\n<h2>1. What Are Common Table Expressions?<\/h2>\n<p>A <strong>Common Table Expression (CTE)<\/strong> is a temporary, named result set defined within the scope of a single <code>SELECT<\/code>, <code>INSERT<\/code>, <code>UPDATE<\/code>, or <code>DELETE<\/code> statement (as well as <code>MERGE<\/code>). Think of a CTE as a more readable, modular alternative to subqueries or derived tables. CTEs help break down intricate logic into smaller, clearer parts.<\/p>\n<p><strong>Basic Syntax<\/strong><\/p>\n<p>The general structure of a CTE in T-SQL looks like this:<\/p>\n<pre><code>WITH cte_name (OptionalColumnList) AS\n(\n    -- A query that returns a result set\n)\nSELECT *\nFROM cte_name;<\/code><\/pre>\n<p>&#8211; <strong>WITH cte_name<\/strong>: Declares the CTE name.<br \/>\n&#8211; <strong>AS ( &#8230; )<\/strong>: Contains a valid SQL query.<br \/>\n&#8211; <strong>SELECT<\/strong>: Consumes the CTE.<\/p>\n<p><strong>Example: A Simple CTE<\/strong><\/p>\n<p>Suppose you want to generate a list of employees who earn above the department average salary. You can compute the average in one query (the CTE) and then reference it in another:<\/p>\n<pre><code>WITH DeptAverages AS\n(\n    SELECT DepartmentID, AVG(Salary) AS AvgSalary\n    FROM Employees\n    GROUP BY DepartmentID\n)\nSELECT e.EmployeeName, e.Salary, da.AvgSalary\nFROM Employees e\nJOIN DeptAverages da\n    ON e.DepartmentID = da.DepartmentID\nWHERE e.Salary &gt; da.AvgSalary;<\/code><\/pre>\n<h2>2. Advantages of CTEs<\/h2>\n<p>CTEs offer several benefits:<\/p>\n<ul>\n<li><strong>Readability<\/strong>: They break down complex queries into logical segments, making code easier to read and maintain.<\/li>\n<li><strong>Reusability within a Single Query<\/strong>: The same CTE can be referenced multiple times within the subsequent query block.<\/li>\n<li><strong>Recursion<\/strong>: They support <em>recursive queries<\/em>, which is especially useful for hierarchy-driven data (e.g., organizational charts, file directories).<\/li>\n<\/ul>\n<p>While temporary tables can offer similar functionality, CTEs are often more straightforward for queries that need temporary data only for a single logical step. A key distinction is that CTEs are not materialized to disk like temp tables; they exist in memory for the duration of the statement. Depending on the complexity of your query, either approach could be optimal, but CTEs typically shine when clarity is paramount.<\/p>\n<h2>3. Introduction to Recursive CTEs<\/h2>\n<p>One of the most compelling uses of CTEs is the capability to <em>reference themselves<\/em>. This allows you to traverse hierarchical data\u2014such as employee-manager relationships or parent-child table structures\u2014without resorting to multiple joins or complex loops.<\/p>\n<p><strong>Recursive CTE Structure<\/strong><\/p>\n<p>A recursive CTE consists of two main parts:<\/p>\n<ol>\n<li><strong>Anchor Member<\/strong>: The initial query that establishes the baseline result set.<\/li>\n<li><strong>Recursive Member<\/strong>: A query that references the CTE itself, extending or iterating the results in each subsequent step.<\/li>\n<\/ol>\n<p>The recursive CTE repeatedly executes the recursive member until no new rows are returned.<\/p>\n<p><strong>General Pattern:<\/strong><\/p>\n<pre><code>WITH cte_name AS\n(\n    -- Anchor member\n    SELECT ...\n    FROM ...\n    WHERE ...\n    \n    UNION ALL\n    \n    -- Recursive member\n    SELECT ...\n    FROM cte_name\n    JOIN ...\n    WHERE ...\n)\nSELECT *\nFROM cte_name;<\/code><\/pre>\n<p><strong>Example: Hierarchical Employee-Manager List<\/strong><\/p>\n<p>Consider a table <code>Employees<\/code> with columns <code>EmployeeID<\/code>, <code>ManagerID<\/code>, and <code>EmployeeName<\/code>. We want to produce a hierarchy that shows each employee and their manager chain:<\/p>\n<pre><code>WITH EmployeeHierarchy AS\n(\n    -- 1. Anchor Member: Start with top-level employees (no manager)\n    SELECT\n        EmployeeID,\n        ManagerID,\n        EmployeeName,\n        0 AS Level\n    FROM Employees\n    WHERE ManagerID IS NULL\n\n    UNION ALL\n\n    -- 2. Recursive Member: Find direct reports by joining back to the CTE\n    SELECT\n        e.EmployeeID,\n        e.ManagerID,\n        e.EmployeeName,\n        eh.Level + 1\n    FROM Employees e\n    JOIN EmployeeHierarchy eh\n        ON e.ManagerID = eh.EmployeeID\n)\nSELECT\n    EmployeeName,\n    ManagerID,\n    Level\nFROM EmployeeHierarchy\nORDER BY Level, EmployeeName;<\/code><\/pre>\n<p>The anchor member returns employees who have no manager (<code>ManagerID IS NULL<\/code>), typically the top of the hierarchy. The recursive member joins the <code>Employees<\/code> table with <code>EmployeeHierarchy<\/code> (the CTE itself) to retrieve each employee who reports to someone in the current result. The <code>Level<\/code> column tracks the depth of each employee in the organizational chart. SQL Server executes the anchor query first, then feeds those results into the recursive query, repeating until no additional rows are found.<\/p>\n<h2>4. Performance Considerations<\/h2>\n<p>While recursive CTEs are powerful, keep the following in mind:<\/p>\n<ul>\n<li><strong>Infinite Loops<\/strong>: A poorly constructed recursive CTE can loop indefinitely. Always include a clear exit condition (for example, referencing a <code>NULL<\/code> manager, a maximum <code>Level<\/code> depth, or a condition that eventually stops returning rows).<\/li>\n<li><strong>Indexing<\/strong>: Hierarchical queries benefit from proper indexing on parent-child columns (e.g., <code>ManagerID<\/code>), which can reduce join costs in recursive steps.<\/li>\n<li><strong>Data Volume<\/strong>: Large data sets may cause performance bottlenecks. For extremely deep hierarchies, consider alternative strategies such as materialized paths or adjacency lists.<\/li>\n<\/ul>\n<h2>5. Practical Tips<\/h2>\n<p>Here are some tips for working with CTEs and recursive queries:<\/p>\n<ul>\n<li><strong>Use Column Aliases Consistently<\/strong>: Consistently alias your tables and columns to avoid confusion and potential naming conflicts.<\/li>\n<li><strong>Test for Logical Loops<\/strong>: Validate or cleanse your data to remove cycles that might cause infinite recursion.<\/li>\n<li><strong>Keep CTEs Focused<\/strong>: Avoid overloading a single CTE with too much logic. If needed, stack multiple CTEs:<\/li>\n<\/ul>\n<pre><code>WITH StepOne AS ( ... ),\n     StepTwo AS ( ... )\nSELECT ...\nFROM StepTwo;<\/code><\/pre>\n<ul>\n<li><strong>Monitor Execution Plans<\/strong>: Use SQL Server\u2019s execution plan to understand how the recursion is processed. If performance issues arise, consider indexing, partitioning, or rewriting parts of the query.<\/li>\n<li><strong>Combine with Window Functions<\/strong>: Window functions (such as <code>ROW_NUMBER()<\/code> or <code>RANK()<\/code>) can further segment or rank data within CTEs, leading to elegant solutions for complex queries.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Common Table Expressions (CTEs) are a valuable construct in T-SQL, offering clarity and modularity for complex queries. By taking advantage of recursive CTEs, you can effectively traverse hierarchical data without resorting to multiple nested queries or iterative code. This approach often yields more maintainable scripts and, with the right indexing, can perform efficiently in many scenarios.<\/p>\n<p>As you integrate CTEs and recursive logic into your T-SQL toolkit, remember to watch for potential pitfalls such as infinite loops and performance issues with large data sets. With careful planning and testing, CTEs become a powerful feature for developers and DBAs aiming to organize and analyze hierarchical relationships within the database.<\/p>\n<p>This wraps up Part 4 of our series on T-SQL programming constructs. Stay tuned for further explorations into advanced topics that can elevate your T-SQL proficiency and help you craft cleaner, more efficient SQL scripts.<\/p>\n<p>Thank you for reading! If you missed the earlier posts in the series, be sure to check them out for foundational topics like variables, loops, <code>CASE<\/code> expressions, and transaction error handling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[84,78,21],"tags":[500,501,503,426,502,337,345,131,344],"class_list":["post-974","post","type-post","status-publish","format-standard","hentry","category-sql-developer","category-tsql","category-tutorial","tag-common-table-expressions","tag-cte","tag-hierarchical-queries","tag-query-optimization","tag-recursive-cte","tag-sql-best-practices","tag-sql-programming","tag-sql-server","tag-t-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk<\/title>\n<meta name=\"description\" content=\"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqltabletalk.com\/?p=974\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk\" \/>\n<meta property=\"og:description\" content=\"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltabletalk.com\/?p=974\" \/>\n<meta property=\"og:site_name\" content=\"SQL Table Talk\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-07T13:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T15:59:47+00:00\" \/>\n<meta name=\"author\" content=\"Stephen Planck\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Stephen Planck\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974\"},\"author\":{\"name\":\"Stephen Planck\",\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0\"},\"headline\":\"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries\",\"datePublished\":\"2025-02-07T13:00:00+00:00\",\"dateModified\":\"2025-02-07T15:59:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974\"},\"wordCount\":932,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0\"},\"keywords\":[\"Common Table Expressions\",\"CTE\",\"Hierarchical Queries\",\"Query Optimization\",\"Recursive CTE\",\"SQL Best Practices\",\"SQL Programming\",\"SQL Server\",\"T-SQL\"],\"articleSection\":[\"SQL Developer\",\"TSQL\",\"Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.sqltabletalk.com\/?p=974#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974\",\"url\":\"https:\/\/www.sqltabletalk.com\/?p=974\",\"name\":\"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/#website\"},\"datePublished\":\"2025-02-07T13:00:00+00:00\",\"dateModified\":\"2025-02-07T15:59:47+00:00\",\"description\":\"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltabletalk.com\/?p=974\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltabletalk.com\/?p=974#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltabletalk.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltabletalk.com\/#website\",\"url\":\"https:\/\/www.sqltabletalk.com\/\",\"name\":\"SQL Table Talk\",\"description\":\"Breaking Down SQL Server, One Post at a Time.\",\"publisher\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltabletalk.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0\",\"name\":\"Stephen Planck\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/64181114edc3de3d99072c049bcec024f025c9536dc89fc8ff1bac58976ca81e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/64181114edc3de3d99072c049bcec024f025c9536dc89fc8ff1bac58976ca81e?s=96&d=mm&r=g\",\"caption\":\"Stephen Planck\"},\"logo\":{\"@id\":\"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/dexterwiki.com\",\"https:\/\/www.linkedin.com\/in\/stephen-planck-4611b692?trk=people-guest_people_search-card&challengeId=AQErf8gbBmcVMwAAAYsyIsxO-0UvU8z7cHrBpZoo_n3xt9qEKpRN5B_jd_LmAMu-OfeArkQ7GDjobJ2uRoQQV35EQdh_rR6kxA&submissionId=09de7067-c335-8e17-40b8-8dc32b60ed6c&challengeSource=AgEcUCw35zpPmAAAAYsyI4vAWhJTV7Nt4vZYKc3V1qiDBpCkKgUvtlOBgYXcE84&challegeType=AgE_wZiTT09IAQAAAYsyI4vDmNvbZIYe6XHju5V2bXVvM3IVxnJslgY&memberId=AgESFTkUShzs_gAAAYsyI4vGYk0Gic1uc5kB6cKOABA26Gw&recognizeDevice=AgHdSZyUSI5CEwAAAYsyI4vKd_koF9JgpsCJShT8QfbK1QMiv8SI\",\"https:\/\/www.youtube.com\/linuxmate\"],\"url\":\"https:\/\/www.sqltabletalk.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk","description":"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqltabletalk.com\/?p=974","og_locale":"en_US","og_type":"article","og_title":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk","og_description":"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.","og_url":"https:\/\/www.sqltabletalk.com\/?p=974","og_site_name":"SQL Table Talk","article_published_time":"2025-02-07T13:00:00+00:00","article_modified_time":"2025-02-07T15:59:47+00:00","author":"Stephen Planck","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Stephen Planck","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqltabletalk.com\/?p=974#article","isPartOf":{"@id":"https:\/\/www.sqltabletalk.com\/?p=974"},"author":{"name":"Stephen Planck","@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0"},"headline":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries","datePublished":"2025-02-07T13:00:00+00:00","dateModified":"2025-02-07T15:59:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqltabletalk.com\/?p=974"},"wordCount":932,"commentCount":0,"publisher":{"@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0"},"keywords":["Common Table Expressions","CTE","Hierarchical Queries","Query Optimization","Recursive CTE","SQL Best Practices","SQL Programming","SQL Server","T-SQL"],"articleSection":["SQL Developer","TSQL","Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sqltabletalk.com\/?p=974#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sqltabletalk.com\/?p=974","url":"https:\/\/www.sqltabletalk.com\/?p=974","name":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries - SQL Table Talk","isPartOf":{"@id":"https:\/\/www.sqltabletalk.com\/#website"},"datePublished":"2025-02-07T13:00:00+00:00","dateModified":"2025-02-07T15:59:47+00:00","description":"Welcome to Part 4 of our ongoing series on T-SQL programming constructs. So far, we\u2019ve discussed variables, conditional IF statements, loops, CASE expressions, and covered essential concepts like error handling and transaction management. Now, we turn to Common Table Expressions (CTEs)\u2014a powerful feature in T-SQL that can simplify complex queries and enable recursion.","breadcrumb":{"@id":"https:\/\/www.sqltabletalk.com\/?p=974#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltabletalk.com\/?p=974"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltabletalk.com\/?p=974#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltabletalk.com\/"},{"@type":"ListItem","position":2,"name":"Exploring Programming Constructs in T-SQL \u2013 Part 4: Common Table Expressions (CTEs) and Recursive Queries"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltabletalk.com\/#website","url":"https:\/\/www.sqltabletalk.com\/","name":"SQL Table Talk","description":"Breaking Down SQL Server, One Post at a Time.","publisher":{"@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltabletalk.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/1947e42a9438bccd91691d8b791888e0","name":"Stephen Planck","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/64181114edc3de3d99072c049bcec024f025c9536dc89fc8ff1bac58976ca81e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/64181114edc3de3d99072c049bcec024f025c9536dc89fc8ff1bac58976ca81e?s=96&d=mm&r=g","caption":"Stephen Planck"},"logo":{"@id":"https:\/\/www.sqltabletalk.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/dexterwiki.com","https:\/\/www.linkedin.com\/in\/stephen-planck-4611b692?trk=people-guest_people_search-card&challengeId=AQErf8gbBmcVMwAAAYsyIsxO-0UvU8z7cHrBpZoo_n3xt9qEKpRN5B_jd_LmAMu-OfeArkQ7GDjobJ2uRoQQV35EQdh_rR6kxA&submissionId=09de7067-c335-8e17-40b8-8dc32b60ed6c&challengeSource=AgEcUCw35zpPmAAAAYsyI4vAWhJTV7Nt4vZYKc3V1qiDBpCkKgUvtlOBgYXcE84&challegeType=AgE_wZiTT09IAQAAAYsyI4vDmNvbZIYe6XHju5V2bXVvM3IVxnJslgY&memberId=AgESFTkUShzs_gAAAYsyI4vGYk0Gic1uc5kB6cKOABA26Gw&recognizeDevice=AgHdSZyUSI5CEwAAAYsyI4vKd_koF9JgpsCJShT8QfbK1QMiv8SI","https:\/\/www.youtube.com\/linuxmate"],"url":"https:\/\/www.sqltabletalk.com\/?author=1"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/posts\/974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=974"}],"version-history":[{"count":3,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/posts\/974\/revisions"}],"predecessor-version":[{"id":978,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=\/wp\/v2\/posts\/974\/revisions\/978"}],"wp:attachment":[{"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqltabletalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}