{"id":3578,"date":"2023-04-12T15:39:33","date_gmt":"2023-04-12T15:39:33","guid":{"rendered":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/"},"modified":"2026-01-15T18:15:51","modified_gmt":"2026-01-15T18:15:51","slug":"exploring-the-sql-cartesian-join","status":"publish","type":"post","link":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/","title":{"rendered":"What Is a SQL Cartesian Join and When Does It Occur in Queries?"},"content":{"rendered":"<p>Joins are an interesting and critical part of understanding and using the SQL language. One of the most curious is the <a href=\"https:\/\/docs.microsoft.com\/en-us\/u-sql\/statements-and-expressions\/select\/from\/joins\/cross-join\">Cartesian join<\/a>.<\/p>\n<p>Simply put, cartesian joins generate a \u201ccartesian product\u201d, which is defined as \u201c\u2026<em>t<\/em><em>he product of two sets: the product of set X and set Y (is) the set that contains all ordered pairs (x, y) for which x belongs to X and y belongs to Y\u2026\u201d.<\/em><\/p>\n<p><strong>SQL Server<\/strong><\/p>\n<p>In SQL Server, the <strong>cartesian product<\/strong> is really a cross-join which returns <em>all the rows in all the tables listed in a query<\/em>:\u00a0 <strong>each<\/strong> row in the first table is paired with <strong>all the rows<\/strong> in the second table.\u00a0 This happens when there is no relationship defined between the two tables.<\/p>\n<p><strong>An Example<\/strong><\/p>\n<p>To best understand this concept, consider the following example.<\/p>\n<p>In a new fast food restaurant, the manager is keen to assign the duty in which each employee is most efficient performing. A database has been created which contains the following three tables:<\/p>\n<p><strong>C_Employee<\/strong> \u2013 holding the restaurant employees<\/p>\n<p><strong>C_Duty<\/strong> \u2013 holding the duties<\/p>\n<p><strong>C_Utilization<\/strong> \u2013 tracking employee utilization by duty<\/p>\n<p>Currently we have only 3 employees:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1445 alignnone\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C1-min.jpg\" alt=\"\" width=\"316\" height=\"105\" \/><\/p>\n<p>And only 3 duties to be performed:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1446 alignnone\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C2-min.jpg\" alt=\"\" width=\"248\" height=\"99\" \/><\/p>\n<p>Using a cartesian join, we can write the following query:<\/p>\n<p>Select EmployeeName<\/p>\n<p>,Duty<\/p>\n<p>from<\/p>\n<p>C_Employee, C_Duty<\/p>\n<p>When we run that query, we receive the expected results (the cartesian product):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1447 alignnone\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C3-min.jpg\" alt=\"\" width=\"382\" height=\"246\" \/><\/p>\n<p>You can see that we have each duty assigned to each employee for a total of 9 rows (3 employees x 3 duties) returned.<\/p>\n<p>Taking this a step further, we know that in the 3<sup>rd<\/sup> table, calculated utilizations for each duty are being entered by Employee ID:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1448 alignnone\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C4-min.jpg\" alt=\"\" width=\"292\" height=\"243\" \/><\/p>\n<p>So, if we introduce a <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/performance\/subqueries?view=sql-server-ver15#:~:text=A%20subquery%20is%20a%20query,SQL%20Copy\">subquery<\/a> into our original query:<\/p>\n<p>Select EmployeeName<\/p>\n<p>,Duty<\/p>\n<p>,(Select Utilization from C_Utilization where<\/p>\n<p>C_Employee.EmployeeID = C_Utilization.EmployeeID<\/p>\n<p>and C_Duty.DutyID = C_Utilization.DutyID) AS &#8216;UTILIZATION&#8217;<\/p>\n<p>from<\/p>\n<p>C_Employee, C_Duty<\/p>\n<p>order by EmployeeName, UTILIZATION DESC<\/p>\n<p>it will add some insight to our results in that we can easily identify which duty is perhaps best for each of our valued employees:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1449 alignnone\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C5-min.jpg\" alt=\"\" width=\"375\" height=\"244\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>So, a JOIN is a SQL\u00a0\u201cclause\u201d that is used to bring together rows from two or more SQL tables, based on a related column between them. The cartesian join is just one type of join. You can learn about all of different SQL joins <a href=\"https:\/\/docs.microsoft.com\/en-us\/u-sql\/statements-and-expressions\/select\/from\/select-selecting-from-joins\">here<\/a>, or look for my next post that explains the use of each type of join.<\/p>\n<p>I hope this little example helped in understanding how a cartesian join it works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Joins are an interesting and critical part of understanding and using the SQL language. One of the most curious is the Cartesian join. Simply put, cartesian joins generate a \u201ccartesian product\u201d, which is defined as \u201c\u2026the product of two sets: the product of set X and set Y (is) the set that contains all ordered&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[27],"tags":[32],"class_list":["post-3578","post","type-post","status-publish","format-standard","hentry","category-quebit-value","tag-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT\" \/>\n<meta property=\"og:description\" content=\"Joins are an interesting and critical part of understanding and using the SQL language. One of the most curious is the Cartesian join. Simply put, cartesian joins generate a \u201ccartesian product\u201d, which is defined as \u201c\u2026the product of two sets: the product of set X and set Y (is) the set that contains all ordered&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/\" \/>\n<meta property=\"og:site_name\" content=\"QueBIT\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-12T15:39:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-15T18:15:51+00:00\" \/>\n<meta name=\"author\" content=\"agoddard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"agoddard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/\"},\"author\":{\"name\":\"agoddard\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\"},\"headline\":\"What Is a SQL Cartesian Join and When Does It Occur in Queries?\",\"datePublished\":\"2023-04-12T15:39:33+00:00\",\"dateModified\":\"2026-01-15T18:15:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/\"},\"wordCount\":429,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/C1-min.jpg\",\"keywords\":[\"SQL\"],\"articleSection\":[\"QueBIT Value\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/\",\"name\":\"What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/C1-min.jpg\",\"datePublished\":\"2023-04-12T15:39:33+00:00\",\"dateModified\":\"2026-01-15T18:15:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/C1-min.jpg\",\"contentUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/C1-min.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/exploring-the-sql-cartesian-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Is a SQL Cartesian Join and When Does It Occur in Queries?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#website\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/\",\"name\":\"QueBIT\",\"description\":\"QueBIT\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\",\"name\":\"agoddard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"caption\":\"agoddard\"},\"sameAs\":[\"https:\\\/\\\/quebit.com\\\/askquebit\"],\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/author\\\/agoddard\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT","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:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/","og_locale":"en_US","og_type":"article","og_title":"What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT","og_description":"Joins are an interesting and critical part of understanding and using the SQL language. One of the most curious is the Cartesian join. Simply put, cartesian joins generate a \u201ccartesian product\u201d, which is defined as \u201c\u2026the product of two sets: the product of set X and set Y (is) the set that contains all ordered&hellip;","og_url":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/","og_site_name":"QueBIT","article_published_time":"2023-04-12T15:39:33+00:00","article_modified_time":"2026-01-15T18:15:51+00:00","author":"agoddard","twitter_card":"summary_large_image","twitter_misc":{"Written by":"agoddard","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#article","isPartOf":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/"},"author":{"name":"agoddard","@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084"},"headline":"What Is a SQL Cartesian Join and When Does It Occur in Queries?","datePublished":"2023-04-12T15:39:33+00:00","dateModified":"2026-01-15T18:15:51+00:00","mainEntityOfPage":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/"},"wordCount":429,"commentCount":0,"image":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#primaryimage"},"thumbnailUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C1-min.jpg","keywords":["SQL"],"articleSection":["QueBIT Value"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/","url":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/","name":"What Is a SQL Cartesian Join and When Does It Occur in Queries? - QueBIT","isPartOf":{"@id":"https:\/\/quebit.com\/askquebit\/#website"},"primaryImageOfPage":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#primaryimage"},"image":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#primaryimage"},"thumbnailUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C1-min.jpg","datePublished":"2023-04-12T15:39:33+00:00","dateModified":"2026-01-15T18:15:51+00:00","author":{"@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084"},"breadcrumb":{"@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#primaryimage","url":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C1-min.jpg","contentUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2021\/05\/C1-min.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/quebit.com\/askquebit\/exploring-the-sql-cartesian-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/quebit.com\/askquebit\/"},{"@type":"ListItem","position":2,"name":"What Is a SQL Cartesian Join and When Does It Occur in Queries?"}]},{"@type":"WebSite","@id":"https:\/\/quebit.com\/askquebit\/#website","url":"https:\/\/quebit.com\/askquebit\/","name":"QueBIT","description":"QueBIT","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/quebit.com\/askquebit\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084","name":"agoddard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","caption":"agoddard"},"sameAs":["https:\/\/quebit.com\/askquebit"],"url":"https:\/\/quebit.com\/askquebit\/author\/agoddard\/"}]}},"_links":{"self":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/comments?post=3578"}],"version-history":[{"count":1,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3578\/revisions"}],"predecessor-version":[{"id":4917,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3578\/revisions\/4917"}],"wp:attachment":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/media?parent=3578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/categories?post=3578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/tags?post=3578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}