{"id":94,"date":"2014-05-10T09:22:00","date_gmt":"2014-05-10T08:22:00","guid":{"rendered":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/10\/what-is-cross-join-in-sql-server\/"},"modified":"2014-05-10T09:22:00","modified_gmt":"2014-05-10T08:22:00","slug":"what-is-cross-join-in-sql-server","status":"publish","type":"post","link":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/10\/what-is-cross-join-in-sql-server\/","title":{"rendered":"What is cross Join in SQL Server?"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>1 Minute, 10 Second                <\/div>\n\n            <\/div><div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"border-bottom: 1px solid rgb(204, 204, 204); border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; margin: 0px; padding: 0px; text-align: right;\" width=\"100%\">\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\">In SQL, the&nbsp;<span style=\"box-sizing: border-box; font-weight: 700;\">CROSS JOIN<\/span>&nbsp;is used to combine each row of the first table with each row of the second table. It is also known as the Cartesian join since it returns the Cartesian product of the sets of rows from the joined tables.<\/span><\/div>\n<\/div>\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\">A cross join is used when you wish to create combination of every row from two tables.&nbsp; All row combinations are included in the result; this is commonly called cross product join.&nbsp; A common use for a cross join is to create obtain all combinations of items.<\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><br \/><\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\">Example-&nbsp;<\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><br \/><\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><span style=\"color: #252525;\">Suppose that we are sitting in a coffee shop and we decide to order breakfast. Shortly, we will look at the menu and we will start thinking of which meal and drink combination could be more tastier. Our brain will receive this signal and begin to generate all meal and drink combinations.<\/span><\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><span style=\"color: #252525;\"><br \/><\/span><\/span><\/div>\n<div style=\"text-align: left;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><span style=\"color: #252525;\"><\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/lh3.googleusercontent.com\/-Dk_KXwXp17w\/YQvuY5oD4oI\/AAAAAAAAMoA\/8kzUXGI5nM8SwfZPj5qIX5a4NP4tb9E6ACLcBGAsYHQ\/image.png\" style=\"margin-left: 1em; margin-right: 1em;\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" data-original-height=\"527\" data-original-width=\"564\" height=\"374\" src=\"https:\/\/lh3.googleusercontent.com\/-Dk_KXwXp17w\/YQvuY5oD4oI\/AAAAAAAAMoA\/8kzUXGI5nM8SwfZPj5qIX5a4NP4tb9E6ACLcBGAsYHQ\/w400-h374\/image.png\" width=\"400\" \/><\/a><\/div>\n<p><\/span><\/span><\/div>\n<\/div>\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\">Unlike the&nbsp;<code style=\"background: rgb(251, 251, 253); border: none; box-shadow: rgba(132, 107, 107, 0.075) 0px 1px 1px; box-sizing: border-box; margin: 0px; padding: 0.25em;\"><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-inner-join\/\" style=\"box-sizing: border-box; text-decoration-line: none; transition: all 0.1s ease-in-out 0s;\" target=\"_blank\" rel=\"noopener\">INNER JOIN<\/a><\/code>&nbsp;or&nbsp;<code style=\"background: rgb(251, 251, 253); border: none; box-shadow: rgba(132, 107, 107, 0.075) 0px 1px 1px; box-sizing: border-box; margin: 0px; padding: 0.25em;\"><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-left-join\/\" style=\"box-sizing: border-box; text-decoration-line: none; transition: all 0.1s ease-in-out 0s;\" target=\"_blank\" rel=\"noopener\">LEFT JOIN<\/a><\/code>, the cross join does not establish a relationship between the joined tables.<\/span><\/div>\n<\/div>\n<pre style=\"background: rgb(245, 245, 245); border: 0px; line-height: 1.4; margin: 20px; outline: 0px; overflow-wrap: break-word; overflow: auto; padding: 20px; text-align: start; vertical-align: baseline; white-space: pre-wrap;\"><div style=\"text-align: left;\"><span style=\"font-family: inherit;\">\n<span face=\"arial, helvetica, sans-serif\">SELECT *<\/span><\/span><\/div><span style=\"font-family: inherit;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\"><div style=\"text-align: left;\">\nFROM   t1<\/div>\n<div style=\"text-align: left;\">\n       CROSS JOIN t2<\/div>\n<\/span><\/span><\/pre>\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\">Suppose you wanted to return a report showing every combination of color and size as shown in our sample data below:<\/span><\/div>\n<\/div>\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><img loading=\"lazy\" decoding=\"async\" alt=\"Cross Join Two Tables to Get Combinations\" height=\"216\" src=\"https:\/\/www.essentialsql.com\/wp-content\/uploads\/2016\/08\/Cross-Join-Two-Tables-to-Get-Combinations.png\" width=\"400\" \/><\/span><\/div>\n<div style=\"text-align: left;\">\n<span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\" style=\"font-family: inherit;\"><br \/><\/span><\/div>\n<\/div>\n<div style=\"background-color: white; box-sizing: border-box; margin-bottom: 26px; padding: 0px; text-align: start;\">\n<div style=\"text-align: left;\">\n<span style=\"font-family: inherit;\"><span face=\"&quot;arial&quot; , &quot;helvetica&quot; , sans-serif\">Source &#8211;&nbsp;<\/span><a href=\"https:\/\/www.essentialsql.com\/cross-join-introduction\/\" style=\"background-color: transparent; text-align: right;\" target=\"_blank\" rel=\"noopener\">https:\/\/www.essentialsql.com\/cross-join-introduction\/<\/a><\/span><\/div>\n<div style=\"text-align: left;\"><span style=\"font-family: inherit;\"><br \/>\nRefer &#8211;&nbsp;<a href=\"https:\/\/www.educative.io\/edpresso\/what-is-the-sql-cross-join\" target=\"_blank\" rel=\"noopener\">https:\/\/www.educative.io\/edpresso\/what-is-the-sql-cross-join<\/a><\/span><\/div>\n<div style=\"text-align: left;\"><span style=\"font-family: inherit;\"><br \/><\/span><\/div>\n<div style=\"text-align: left;\"><span style=\"font-family: inherit;\">for run time example-<\/span><\/div>\n<div style=\"text-align: left;\"><a href=\"https:\/\/www.sqlshack.com\/sql-cross-join-with-examples\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-family: inherit;\">https:\/\/www.sqlshack.com\/sql-cross-join-with-examples\/<\/span><\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In SQL, the&nbsp;CROSS JOIN&nbsp;is used to combine each row of the first table with each row of the second table. It is also known as the Cartesian join since it returns the Cartesian product of the sets of rows from the joined tables. A cross join is used when you wish to create combination of [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[34,38,27],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-ibm","category-sakon","category-sql"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Himanshu Namdeo","author_link":"https:\/\/debuggersspace.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"In SQL, the&nbsp;CROSS JOIN&nbsp;is used to combine each row of the first table with each row of the second table. It is also known as the Cartesian join since it returns the Cartesian product of the sets of rows from the joined tables. A cross join is used when you wish to create combination of&hellip;","_links":{"self":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":0,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}