{"id":1435,"date":"2012-12-19T10:00:18","date_gmt":"2012-12-19T15:00:18","guid":{"rendered":"http:\/\/sqlity.net\/en\/?p=1435"},"modified":"2015-01-02T12:08:53","modified_gmt":"2015-01-02T17:08:53","slug":"a-join-a-day-nested-joins","status":"publish","type":"post","link":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/","title":{"rendered":"A Join A Day \u2013 Nested Joins"},"content":{"rendered":"<div>\n<h3>Introduction<\/h3>\n<p>\nThis is the nineteenth post in my <a href=\"http:\/\/sqlity.net\/en\/1146\/a-join-a-day-introduction\/\">A Join A Day<\/a> series about SQL Server Joins. Make sure to let me know how I am doing or ask your burning join related questions by leaving a comment below.\n<\/p>\n<p>\nMost of the examples so far have dealt with joins between two tables. In this post we are going to take a look at queries that involve more than two tables.\n<\/p>\n<h3>Nested Join Example<\/h3>\n<p>\nEach join in a query takes two inputs, so if a query contains more than two tables, there needs to be an additional join for each additional table, using one of its inputs for the new table and one to link to the existing tables:\n<\/p>\n<div>\n[sql]\nSELECT  pers.FirstName,<br \/>\n        pers.LastName,<br \/>\n        cust.AccountNumber,<br \/>\n        soh.OrderDate,<br \/>\n        sod.OrderQty,<br \/>\n        sod.LineTotal,<br \/>\n        prod.Name,<br \/>\n        prod.ListPrice<br \/>\nFROM    Sales.SalesOrderHeader AS soh<br \/>\nJOIN    Sales.SalesOrderDetail AS sod<br \/>\n        ON soh.SalesOrderID = sod.SalesOrderID<br \/>\nJOIN    Production.Product AS prod<br \/>\n        ON sod.ProductID = prod.ProductID<br \/>\nJOIN    Sales.Customer AS cust<br \/>\n        ON soh.CustomerID = cust.CustomerID<br \/>\nJOIN    Person.Person AS pers<br \/>\n        ON cust.PersonID = pers.BusinessEntityID<br \/>\nORDER BY pers.BusinessEntityID, soh.SalesOrderID, sod.SalesOrderDetailID;<br \/>\n[\/sql]\n<\/div>\n<p>\nIn this example we have five tables joined together. After the first one each additional one has its own <span class=\"tt\">JOIN<\/span> section and its own join condition.\n<\/p>\n<h3>Nested Join Syntax<\/h3>\n<p>\nThere are several ways to write a query with several joins. There is the chained approach in which each additional table is just added at the end. This is the syntax used most often.\n<\/p>\n<p>\nAnother option is to group tables together in sub-queries like this:\n<\/p>\n<div>\n[sql]\nSELECT  cp.FirstName,<br \/>\n        cp.LastName,<br \/>\n        cp.AccountNumber,<br \/>\n        so.OrderDate,<br \/>\n        so.OrderQty,<br \/>\n        so.LineTotal,<br \/>\n        prod.Name,<br \/>\n        prod.ListPrice<br \/>\nFROM    (<br \/>\n          SELECT  soh.OrderDate,<br \/>\n                  sod.OrderQty,<br \/>\n                  sod.LineTotal,<br \/>\n                  sod.ProductID,<br \/>\n                  soh.CustomerID,<br \/>\n                  soh.SalesOrderID,<br \/>\n                  sod.SalesOrderDetailID<br \/>\n          FROM    Sales.SalesOrderHeader AS soh<br \/>\n          JOIN    Sales.SalesOrderDetail AS sod<br \/>\n                  ON soh.SalesOrderID = sod.SalesOrderID<br \/>\n        ) AS so<br \/>\nJOIN    Production.Product AS prod<br \/>\n        ON so.ProductID = prod.ProductID<br \/>\nJOIN    (<br \/>\n          SELECT  cust.CustomerID,<br \/>\n                  cust.AccountNumber,<br \/>\n                  pers.FirstName,<br \/>\n                  pers.LastName,<br \/>\n                  pers.BusinessEntityID<br \/>\n          FROM    Sales.Customer AS cust<br \/>\n          JOIN    Person.Person AS pers<br \/>\n                  ON cust.PersonID = pers.BusinessEntityID<br \/>\n        ) AS cp<br \/>\n        ON so.CustomerID = cp.CustomerID<br \/>\nORDER BY cp.BusinessEntityID, so.SalesOrderID, so.SalesOrderDetailID;<br \/>\n[\/sql]\n<\/div>\n<p>\nYou can even go a step further with this and move each group into its own CTE:\n<\/p>\n<div>\n[sql]\nWITH  cp AS (<br \/>\n             SELECT cust.CustomerID,<br \/>\n                    cust.AccountNumber,<br \/>\n                    pers.FirstName,<br \/>\n                    pers.LastName,<br \/>\n                    pers.BusinessEntityID<br \/>\n             FROM   Sales.Customer AS cust<br \/>\n             JOIN   Person.Person AS pers<br \/>\n                    ON cust.PersonID = pers.BusinessEntityID<br \/>\n           ),<br \/>\n      so AS (<br \/>\n             SELECT soh.OrderDate,<br \/>\n                    sod.OrderQty,<br \/>\n                    sod.LineTotal,<br \/>\n                    sod.ProductID,<br \/>\n                    soh.CustomerID,<br \/>\n                    soh.SalesOrderID,<br \/>\n                    sod.SalesOrderDetailID<br \/>\n             FROM   Sales.SalesOrderHeader AS soh<br \/>\n             JOIN   Sales.SalesOrderDetail AS sod<br \/>\n                    ON soh.SalesOrderID = sod.SalesOrderID<br \/>\n           )<br \/>\n  SELECT  cp.FirstName,<br \/>\n          cp.LastName,<br \/>\n          cp.AccountNumber,<br \/>\n          so.OrderDate,<br \/>\n          so.OrderQty,<br \/>\n          so.LineTotal,<br \/>\n          prod.Name,<br \/>\n          prod.ListPrice<br \/>\n  FROM    so<br \/>\n  JOIN    Production.Product AS prod<br \/>\n          ON so.ProductID = prod.ProductID<br \/>\n  JOIN    cp<br \/>\n          ON so.CustomerID = cp.CustomerID<br \/>\n  ORDER BY cp.BusinessEntityID, so.SalesOrderID, so.SalesOrderDetailID;<br \/>\n[\/sql]\n<\/div>\n<p>\nThe third and probably least well known option allows you to directly break the joins into several groups:\n<\/p>\n<div>\n[sql]\nSELECT  pers.FirstName,<br \/>\n        pers.LastName,<br \/>\n        cust.AccountNumber,<br \/>\n        soh.OrderDate,<br \/>\n        sod.OrderQty,<br \/>\n        sod.LineTotal,<br \/>\n        prod.Name,<br \/>\n        prod.ListPrice<br \/>\nFROM    Production.Product AS prod<br \/>\nJOIN    (<br \/>\n        Sales.SalesOrderHeader AS soh<br \/>\n        JOIN Sales.SalesOrderDetail AS sod<br \/>\n          ON soh.SalesOrderID = sod.SalesOrderID<br \/>\n        )<br \/>\n        ON sod.ProductID = prod.ProductID<br \/>\nJOIN    (<br \/>\n        Sales.Customer AS cust<br \/>\n        JOIN Person.Person AS pers<br \/>\n          ON cust.PersonID = pers.BusinessEntityID<br \/>\n        )<br \/>\n        ON soh.CustomerID = cust.CustomerID<br \/>\nORDER BY pers.BusinessEntityID, soh.SalesOrderID, sod.SalesOrderDetailID;<br \/>\n[\/sql]\n<\/div>\n<p>\nIn this last example the parentheses are optional, but removing them makes the query harder to read and understand.\n<\/p>\n<p>\nOf the four examples above, the last one is probably the easiest to comprehend, however this syntax style can backfire too.<br \/>\nCheck out this T-SQL Tuesday post for a fairly simple example that shows how you should not use this syntax style (and how to make it better): <a href=\"http:\/\/mickeystuewe.com\/2012\/12\/11\/t-sql-tuesday-37-right-join-left-join-raw-raw-raw\/\" target=\"_blank\">http:\/\/mickeystuewe.com\/2012\/12\/11\/t-sql-tuesday-37-right-join-left-join-raw-raw-raw\/<\/a>\n<\/p>\n<p>\nAll the above queries are equivalent. The order of joins in a query does not change the result. In fact, the SQL Server optimizer often reorders the tables when building an execution plan. In this example all four queries end up using the same plan. So the only reason to use the one syntax over the other is readability for us humans. Keep that in mind when writing your joins and make sure that your improvement is not ending up being a <a href=\"http:\/\/www.urbandictionary.com\/define.php?term=Verschlimmbesserung\">Verschlimmbesserung<\/a>.\n<\/p>\n<h3>Nested Join Operators<\/h3>\n<p>\nEach join operator that SQL Server can use to build an execution plan also can only handle two row sources. However, there are many different options to chain these operators together. The execution plan for the example queries above looks like this:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan.jpg\" alt=\"a multi-join execution plan\" title=\"a multi-join execution plan\" width=\"1920\" height=\"1138\" class=\"aligncenter size-full wp-image-1439\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan.jpg 1920w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan-300x177.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan-1024x606.jpg 1024w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/multi-join-execution-plan-150x88.jpg 150w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/a>\n<\/p>\n<p>\nEach join operator acts as first input to the next operator. The second input is always a single table.<br \/>\nThere are a few additional operators like a Sort or a Compute Scalar in there that you can ignore for this discussion.\n<\/p>\n<p>\nThe above execution plan is in the form of a left deep tree:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/left-deep-join-tree.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/left-deep-join-tree.jpg\" alt=\"a left-deep join tree\" title=\"a left-deep join tree\" width=\"400\" height=\"610\" class=\"aligncenter size-full wp-image-1438\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/left-deep-join-tree.jpg 400w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/left-deep-join-tree-196x300.jpg 196w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/left-deep-join-tree-98x150.jpg 98w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a>\n<\/p>\n<p>\nSQL Server could in theory create an execution plan where the joins are more evenly distributed. Such an execution plan would have the shape of a bushy tree:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree.jpg\" alt=\"a bushy join tree\" title=\"a bushy join tree\" width=\"439\" height=\"549\" class=\"aligncenter size-full wp-image-1436\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree.jpg 439w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-239x300.jpg 239w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-119x150.jpg 119w\" sizes=\"auto, (max-width: 439px) 100vw, 439px\" \/><\/a>\n<\/p>\n<p>\nHowever, SQL Server tries to avoid those kinds of plans. While there are queries where a bushy tree would be more efficient, bushy execution plans can have problems like a significantly increased requirement for memory. Therefore you will rarely see them when working with SQL Server.\n<\/p>\n<p>\nTo demonstrate that they exist, I modified the example query above with a join hint (tomorrow's topic):\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example.jpg\" alt=\"a bushy hash join execution plan\" title=\"a bushy hash join execution plan\" width=\"1920\" height=\"1138\" class=\"aligncenter size-full wp-image-1441\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example.jpg 1920w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example-300x177.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example-1024x606.jpg 1024w, https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-hash-join-tree-example-150x88.jpg 150w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/a>\n<\/p>\n<p>\nEven though SQL Server avoids bushy plans, it does not only use left deep trees either. You will also see right deep trees or even alternating trees equally often. In most cases however at least one input to each join operator is coming directly from a table and not from another join.\n<\/p>\n<h3>Summary<\/h3>\n<p>\nThe T-SQL language allows us to join multiple tables together in a single query. After the first table, each additional one requires its own join statement and its own join condition. There are many ways to write a multi table join and group related tables together. However all result in the same logical query.\n<\/p>\n<p>\nOn the physical side, each join is represented by a single join operator. Each operator takes exactly two inputs. As changing the order of the tables in a multi join does not change the result, the optimizer will often use a different physical order in the execution plan than the order in which the tables are mentioned in the query.\n<\/p>\n<p>\nIn most execution plans each join operator will have at least one input sub-tree that does not contain another join operator. However, it is possible to get a bushy join tree too.\n<\/p>\n<h3>A Join A Day<\/h3>\n<p>\nThis post is part of my December 2012 \"A Join A Day\" blog post series. You can find the table of contents with all posts published so far in the introductory post: <a href=\"http:\/\/sqlity.net\/en\/1146\/a-join-a-day-introduction\/\">A Join A Day \u2013 Introduction<\/a>. Check back there frequently throughout the month.\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.<\/p>\n<p> <a href=\"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/\">[more&#8230;]<\/a><\/p>\n","protected":false},"author":3,"featured_media":1437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[28,29,5,27],"tags":[],"class_list":["post-1435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-a-join-a-day","category-fundamentals","category-general","category-series"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Join A Day \u2013 Nested Joins - sqlity.net<\/title>\n<meta name=\"description\" content=\"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Join A Day \u2013 Nested Joins - sqlity.net\" \/>\n<meta property=\"og:description\" content=\"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/\" \/>\n<meta property=\"og:site_name\" content=\"sqlity.net\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sqlity.net\" \/>\n<meta property=\"article:published_time\" content=\"2012-12-19T15:00:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-01-02T17:08:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1138\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Meine\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sqlity\" \/>\n<meta name=\"twitter:site\" content=\"@sqlity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Meine\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/\"},\"author\":{\"name\":\"Sebastian Meine\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"headline\":\"A Join A Day \u2013 Nested Joins\",\"datePublished\":\"2012-12-19T15:00:18+00:00\",\"dateModified\":\"2015-01-02T17:08:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/\"},\"wordCount\":1181,\"commentCount\":4,\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/bushy-join-tree-example.jpg\",\"articleSection\":[\"A Join A Day\",\"Fundamentals\",\"General\",\"Series\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/\",\"name\":\"A Join A Day \u2013 Nested Joins - sqlity.net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/bushy-join-tree-example.jpg\",\"datePublished\":\"2012-12-19T15:00:18+00:00\",\"dateModified\":\"2015-01-02T17:08:53+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"description\":\"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/bushy-join-tree-example.jpg\",\"contentUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/bushy-join-tree-example.jpg\",\"width\":\"1920\",\"height\":\"1138\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1435\\\/a-join-a-day-nested-joins\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Join A Day \u2013 Nested Joins\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\",\"name\":\"sqlity.net\",\"description\":\"Quality for SQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sqlity.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\",\"name\":\"Sebastian Meine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"caption\":\"Sebastian Meine\"},\"sameAs\":[\"http:\\\/\\\/sqlity.net\",\"https:\\\/\\\/x.com\\\/sqlity\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Join A Day \u2013 Nested Joins - sqlity.net","description":"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.","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:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/","og_locale":"en_US","og_type":"article","og_title":"A Join A Day \u2013 Nested Joins - sqlity.net","og_description":"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.","og_url":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/","og_site_name":"sqlity.net","article_publisher":"https:\/\/www.facebook.com\/sqlity.net","article_published_time":"2012-12-19T15:00:18+00:00","article_modified_time":"2015-01-02T17:08:53+00:00","og_image":[{"width":1920,"height":1138,"url":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","type":"image\/jpeg"}],"author":"Sebastian Meine","twitter_card":"summary_large_image","twitter_creator":"@sqlity","twitter_site":"@sqlity","twitter_misc":{"Written by":"Sebastian Meine","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#article","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/"},"author":{"name":"Sebastian Meine","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"headline":"A Join A Day \u2013 Nested Joins","datePublished":"2012-12-19T15:00:18+00:00","dateModified":"2015-01-02T17:08:53+00:00","mainEntityOfPage":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/"},"wordCount":1181,"commentCount":4,"image":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","articleSection":["A Join A Day","Fundamentals","General","Series"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/","url":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/","name":"A Join A Day \u2013 Nested Joins - sqlity.net","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#primaryimage"},"image":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","datePublished":"2012-12-19T15:00:18+00:00","dateModified":"2015-01-02T17:08:53+00:00","author":{"@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"description":"When joining more than two tables together, one additional JOIN key word is needed for each new table. there are many ways to group the tables in a join query together effectively building nested joins. However, the order or even grouping of tables does not change the query. Indeed, the query optimizer often makes use of that and produces an execution plan in which the order of the tables does not match the order in which they are mentioned in the query.","breadcrumb":{"@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#primaryimage","url":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","contentUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","width":"1920","height":"1138"},{"@type":"BreadcrumbList","@id":"https:\/\/sqlity.net\/en\/1435\/a-join-a-day-nested-joins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sqlity.net\/en\/"},{"@type":"ListItem","position":2,"name":"A Join A Day \u2013 Nested Joins"}]},{"@type":"WebSite","@id":"https:\/\/sqlity.net\/en\/#website","url":"https:\/\/sqlity.net\/en\/","name":"sqlity.net","description":"Quality for SQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sqlity.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c","name":"Sebastian Meine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","caption":"Sebastian Meine"},"sameAs":["http:\/\/sqlity.net","https:\/\/x.com\/sqlity"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/sqlity.net\/wp-content\/uploads\/2012\/12\/bushy-join-tree-example.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2wXuw-n9","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/1435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/comments?post=1435"}],"version-history":[{"count":0,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/1435\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media\/1437"}],"wp:attachment":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media?parent=1435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/categories?post=1435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/tags?post=1435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}