<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":968,"date":"2021-07-18T20:27:46","date_gmt":"2021-07-18T20:27:46","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=968"},"modified":"2021-09-09T09:28:35","modified_gmt":"2021-09-09T09:28:35","slug":"what-is-the-difference-between-join-and-union","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/","title":{"rendered":"What is the Difference between join and union ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"union\" class=\"color-pink\" style=\"text-align: justify;\"><span style=\"font-family: inherit; font-size: 2rem;\">Union<\/span><\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>The union operator combines the results of two or more queries into a single result set. But no.of columns must match in both\/all the queries (and also the order) which are used for union.<\/li>\n<li>We can union two tables irrespective of common field.<\/li>\n<li>The UNION set operator is used for combining data from two tables which have columns with the same datatype.\n<ul>\n<li>Union &#8211; Returns with no duplicate rows.<\/li>\n<li>Union all &#8211; Retruns with duplicate rows (No. of rows returned = No. of rows in Query1 + No. of rows in Query 2).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"ImageContent\">\n<div class=\"hddn\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-medium aligncenter\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg\" alt=\"Union unionall except intersect\" width=\"781\" height=\"156\" \/><\/div>\n<\/div>\n<ul>\n<li>We cannot use the union operator within a create view statement.<\/li>\n<li>We cannot use the union operator on text and image columns.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"ImageContent\" style=\"text-align: justify;\">\n<div class=\"hddn\"><img decoding=\"async\" class=\"alignnone size-medium aligncenter\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-command-sql.gif\" alt=\"Union in SQL\" width=\"345\" height=\"225\" \/><\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"syntax\" class=\"color-blue\">Syntax<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT expression1, expression2, ... expression_n<br\/>FROM tables<br\/>[WHERE conditions]<br\/>UNION<br\/>SELECT expression1, expression2, ... expression_n<br\/>FROM tables<br\/>[WHERE conditions];<\/code><\/pre> <\/div>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"join\" class=\"color-blue\">Join<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>Joins are used to extract information from more than one table based on the related column\/coloums (PK and RFK) any no. of rows can be retrived based on matching colums.<\/li>\n<li>We can join two tables by &#8216;join&#8217; if they have common field.<\/li>\n<li>A Join is used for displaying columns with the same or different names from different tables.<\/li>\n<li>Different types of joins are\u00a0Inner join=equi join=join ,\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/sql\/outer-join-in-sql\">outer join<\/a> (Right outer join\/right join,\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/sql\/left-outer-join-in-sql\">Left outer join<\/a> \/ left join),\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/sql\/cross-join\">Cross join<\/a> , and full outer join\/outer join.<\/li>\n<li>We can use join operator within a create view statement.<\/li>\n<li>We can use the join operator on text and image columns.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"ImageContent\" style=\"text-align: justify;\">\n<div class=\"hddn\"><img decoding=\"async\" class=\"alignnone size-medium aligncenter\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/cross-join.png\" alt=\"Cross Join\" width=\"341\" height=\"213\" \/><\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"syntax-2\" class=\"color-blue\">Syntax<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT column-names<br\/>FROM table-name1 JOIN table-name2 <br\/>ON column-name1 = column-name2<br\/>WHERE condition<\/code><\/pre> <\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : The union operator combines the results of two or more queries into a single result set&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[6547],"tags":[195,6595,203,199,214,198,209,283,205,6742,6787,6743,6744,6745,6746,2936,222,6775,484,196,212,6776,6772,6773,286,6778,6777,970,207,6771,6747,6784,6748,6749,6750,204,6751,6774,6752,282,208,288,206,6753,6754,6767,6755,6630,6756,6770,6769,6757,6758,6768,6779,6781,6759,6760,6761,6762,6763,975,200,6780,6786,6764,6765,6766,6783,197,284,280,364,6785,6782,285,15907],"class_list":["post-968","post","type-post","status-publish","format-standard","hentry","category-sql","tag-accenture-interview-questions-and-answers","tag-allstate-solut-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-collabera-technologies-interview-questions-and-answers","tag-conduent-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-difference-between-cartesian-product-and-union","tag-difference-between-join-and-union","tag-difference-between-join-and-union-with-example","tag-difference-between-or-and-union-in-sql","tag-difference-between-union-all-and-union","tag-difference-between-union-and-full-outer-joinfull-outer-join-vs-union-all-performance","tag-fis-global-business-solutions-india-pvt-ltd-interview-questions-and-answers","tag-flipkart-interview-questions-and-answers","tag-full-outer-join","tag-genpact-interview-questions-and-answers","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-inner-join","tag-join","tag-joins","tag-lt-infotech-interview-questions-and-answers","tag-left-join","tag-left-outer-join","tag-mindtree-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-mysql-inner-join","tag-mysql-join","tag-mysql-union","tag-mysql-union-example","tag-mysql-union-join-difference","tag-natural-join-in-sql","tag-oracle-corporation-interview-questions-and-answers","tag-oracle-sql-union","tag-outer-join","tag-outer-join-in-sql","tag-persistent-systems-interview-questions-and-answers","tag-prokarma-softech-pvt-ltd-interview-questions-and-answers","tag-r-systems-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-self-join-in-sql","tag-sql-full-join","tag-sql-inner-join","tag-sql-inner-join-where","tag-sql-join","tag-sql-join-3-tables","tag-sql-join-types","tag-sql-left-join","tag-sql-left-outer-join","tag-sql-multiple-joins","tag-sql-outer-join","tag-sql-union","tag-sql-union-all","tag-sql-union-all-example","tag-sql-union-distinct","tag-sql-union-order-by","tag-sql-union-vs-join","tag-sql-union-vs-union-all","tag-tata-consultancy-service-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-trade-union","tag-union-all","tag-union-and-join-together-in-sql","tag-union-in-sql-server","tag-union-vs-join-performance","tag-unions","tag-unitedhealth-group-interview-questions-and-answers","tag-valuelabs-interview-questions-and-answers","tag-virtusa-consulting-services-pvt-ltd-interview-questions-and-answers","tag-wells-fargo-interview-questions-and-answers","tag-what-is-a-union","tag-workers-union","tag-xoriant-solutions-pvt-ltd-interview-questions-and-answers","tag-xt-global-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is the Difference between join and union ? - SQL - Wikitechy<\/title>\n<meta name=\"description\" content=\"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.\" \/>\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.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the Difference between join and union ? - SQL - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-18T20:27:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-09T09:28:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/\",\"name\":\"What is the Difference between join and union ? - SQL - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg\",\"datePublished\":\"2021-07-18T20:27:46+00:00\",\"dateModified\":\"2021-09-09T09:28:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage\",\"url\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg\",\"contentUrl\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg\"},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the Difference between join and union ? - SQL - Wikitechy","description":"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.","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.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/","og_locale":"en_US","og_type":"article","og_title":"What is the Difference between join and union ? - SQL - Wikitechy","og_description":"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/","og_site_name":"Wikitechy","article_published_time":"2021-07-18T20:27:46+00:00","article_modified_time":"2021-09-09T09:28:35+00:00","og_image":[{"url":"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg"}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/","name":"What is the Difference between join and union ? - SQL - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg","datePublished":"2021-07-18T20:27:46+00:00","dateModified":"2021-09-09T09:28:35+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"What is the Difference between join and union ? - The union operator combines the results of two or more queries into a single result set.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/what-is-the-difference-between-join-and-union\/#primaryimage","url":"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg","contentUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/sql\/union-unionall-except-intersect.jpg"},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=968"}],"version-history":[{"count":4,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/968\/revisions"}],"predecessor-version":[{"id":3168,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/968\/revisions\/3168"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}