{"id":540,"date":"2024-02-12T09:47:29","date_gmt":"2024-02-12T01:47:29","guid":{"rendered":"https:\/\/datascihubs.com\/?p=540"},"modified":"2024-02-15T21:11:42","modified_gmt":"2024-02-15T13:11:42","slug":"sql-join-a-complete-guide-with-examples","status":"publish","type":"post","link":"https:\/\/datascihubs.com\/index.php\/2024\/02\/12\/sql-join-a-complete-guide-with-examples\/","title":{"rendered":"SQL JOIN: A Complete Guide With Examples"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1-1024x576.png?resize=1024%2C576&#038;ssl=1\" alt=\"SQL Join\" class=\"wp-image-912\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\"><strong>SQL JOIN<\/strong> is a powerful operation that combines data from multiple tables in a database based on a specified relationship between them. It&#8217;s like merging different pieces of information to create a comprehensive view. There are different types of joins, each serving a unique purpose:<\/p>\n\n\n\n<p><strong>INNER JOIN<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2-1024x576.png?resize=1024%2C576&#038;ssl=1\" alt=\"Inner Join\" class=\"wp-image-913\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/2.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">This type returns only the rows where there is a match between the specified columns in both tables. It&#8217;s like getting a list of students who are also club members.<\/p>\n\n\n\n<p><strong>LEFT JOIN (or LEFT OUTER JOIN)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3-1024x576.png?resize=1024%2C576&#038;ssl=1\" alt=\"Left Join\" class=\"wp-image-914\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/3.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">This returns all rows from the left table and the matching rows from the right table. NULL values are returned if there&#8217;s no match in the right table. It&#8217;s like listing all students and their club memberships, even if some aren&#8217;t in a club. <\/p>\n\n\n\n<p><strong>RIGHT JOIN (or RIGHT OUTER JOIN)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4-1024x576.png?resize=1024%2C576&#038;ssl=1\" alt=\"Right Join\" class=\"wp-image-915\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/4.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Similar to the LEFT JOIN, it returns all rows from the right table and the matching rows from the left table. It&#8217;s like listing all club memberships and the students who are part of them.<\/p>\n\n\n\n<p><strong>FULL OUTER JOIN<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5-1024x576.png?resize=1024%2C576&#038;ssl=1\" alt=\"Full Outer Join\" class=\"wp-image-916\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/5.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">This returns all rows from both tables, with NULL values in places where there&#8217;s no match. It&#8217;s like combining a list of all students and a list of all club memberships, showing both who&#8217;s in a club and who isn&#8217;t.<\/p>\n\n\n\n<p><strong>CROSS JOIN (or CARTESIAN JOIN)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1498\" height=\"843\" src=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6-1024x576.png?resize=1498%2C843&#038;ssl=1\" alt=\"Cross Join\" class=\"wp-image-917\" srcset=\"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?resize=600%2C338&amp;ssl=1 600w, https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/6.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 1498px) 100vw, 1498px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">This generates a cartesian product of two tables, meaning every row from the left table is paired with every row from the right table. It&#8217;s like making all possible combinations of students and clubs, even if they don&#8217;t match.<\/p>\n\n\n\n<p>If you wish to learn more about how SQL works in databases, please visit this <a href=\"https:\/\/datascihubs.com\/index.php\/2024\/01\/13\/the-big-picture-of-structured-query-language\/\" target=\"_blank\" rel=\"noopener\" title=\"\">post<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL JOIN is a powerful operation that combines data from multiple tables in a database based on a specified relationship between them. It&#8217;s like merging different pieces of information to create a comprehensive view. There are different types of joins, each serving a unique purpose: INNER JOIN This type returns only the rows where there [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":912,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"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":"","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}},"categories":[1],"tags":[28,101,102,94],"class_list":["post-540","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information","tag-data-analysis","tag-database","tag-join","tag-sql"],"blocksy_meta":[],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/datascihubs.com\/wp-content\/uploads\/2024\/02\/1.png?fit=1920%2C1080&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/posts\/540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/comments?post=540"}],"version-history":[{"count":2,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":918,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/posts\/540\/revisions\/918"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/media\/912"}],"wp:attachment":[{"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/media?parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/categories?post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datascihubs.com\/index.php\/wp-json\/wp\/v2\/tags?post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}