

{"id":12509,"date":"2018-04-10T05:12:36","date_gmt":"2018-04-10T05:12:36","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=12509"},"modified":"2021-05-09T13:11:01","modified_gmt":"2021-05-09T07:41:01","slug":"impala-union-clause","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/","title":{"rendered":"Introduction to Impala UNION Clause with Example"},"content":{"rendered":"<p><span style=\"font-weight: 400\">While it comes to combine the results of two queries in <strong>Impala<\/strong>, we use Impala UNION Clause. There is much more to learn about Impala UNION Clause. So, let\u2019s learn about it from this article. Apart from its introduction, it includes its syntax, type as well as its example, to understand it well.<\/span><\/p>\n<p>So, let&#8217;s start Impala UNION Clause tutorial.<\/p>\n<h2><span style=\"font-weight: 400\">Introduction to Impala UNION Clause<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Basically, in order to combine the result sets of multiple queries, we use the Impala UNION clause. Although, the result sets are combined by default as if the DISTINCT operator was applied.<\/span><br \/>\n<span style=\"font-weight: 400\">In other words, to combine the results of two queries we the Impala Union clause.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Syntax<\/span><\/h2>\n<p><span style=\"font-weight: 400\">So, the syntax for using Impala UNION Clause is-<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><b>query_1 UNION [DISTINCT | ALL] query_2<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Usage<\/span><\/h2>\n<p><span style=\"font-weight: 400\">We can say, UNION DISTINCT and the UNION keyword by itself is similar. Always, \u00a0prefer UNION ALL where practical, because eliminating duplicates can be a memory-intensive process for a large result set.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> Especially, where the duplicate values are acceptable or when you know the different queries in the union will not produce any duplicates.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">However, \u00a0in Impala 1.4 and higher, we do not need the LIMIT clause while an ORDER BY clause applies to a UNION ALL or UNION query. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, turn the UNION query into a subquery, SELECT from the subquery, and put the ORDER BY clause at the end, outside the subquery, in order to make the ORDER BY and LIMIT clauses apply to the entire result set.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Example<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Impala UNION Clause Example,<\/span><br \/>\n<span style=\"font-weight: 400\">Let\u2019s suppose we have a table named <\/span><b>Students<\/b><span style=\"font-weight: 400\"> in the database my_db. Its contents are\u2212<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><b>[quickstart.cloudera:21000] &gt; select * from Students; <\/b><b><br \/>\n<\/b><b>Query: select * from Students <\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>address<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>shubham<\/b><\/td>\n<td><b>32<\/b><\/td>\n<td><b>delhi<\/b><\/td>\n<td><b>20000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>9<\/b><\/td>\n<td><b>Pulkit<\/b><\/td>\n<td><b>23<\/b><\/td>\n<td><b>Gandhi nagar<\/b><\/td>\n<td><b>28000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>monika<\/b><\/td>\n<td><b>25<\/b><\/td>\n<td><b>mumbai<\/b><\/td>\n<td><b>15000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><b>revti<\/b><\/td>\n<td><b>25<\/b><\/td>\n<td><b>indore<\/b><\/td>\n<td><b>35000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>7<\/b><\/td>\n<td><b>Vaishnavi<\/b><\/td>\n<td><b>25<\/b><\/td>\n<td><b>Goa<\/b><\/td>\n<td><b>23000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>mehul<\/b><\/td>\n<td><b>22<\/b><\/td>\n<td><b>hyderabad<\/b><\/td>\n<td><b>32000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>8<\/b><\/td>\n<td><b>Rishabh<\/b><\/td>\n<td><b>22<\/b><\/td>\n<td><b>chennai<\/b><\/td>\n<td><b>31000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>5<\/b><\/td>\n<td><b>shreyash<\/b><\/td>\n<td><b>23<\/b><\/td>\n<td><b>pune<\/b><\/td>\n<td><b>30000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><b>kajal<\/b><\/td>\n<td><b>27<\/b><\/td>\n<td><b>alirajpur<\/b><\/td>\n<td><b>40000<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Fetched 9 row(s) in 0.59s<\/b><br \/>\n<span style=\"font-weight: 400\">Similarly, \u00a0assume we have another table named <\/span><b>Users<\/b><span style=\"font-weight: 400\">. Its contents are \u2212<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><b>[quickstart.cloudera:21000] &gt; select * from Users; <\/b><b><br \/>\n<\/b><b>Query: select * from Users <\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>address<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><b>vishal<\/b><\/td>\n<td><b>54<\/b><\/td>\n<td><b>Banglore<\/b><\/td>\n<td><b>55000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>Shubham<\/b><\/td>\n<td><b>44<\/b><\/td>\n<td><b>Banglore<\/b><\/td>\n<td><b>50000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><b>Mansi<\/b><\/td>\n<td><b>64<\/b><\/td>\n<td><b>kolkata<\/b><\/td>\n<td><b>60000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>Ankur<\/b><\/td>\n<td><b>34<\/b><\/td>\n<td><b>kolkata<\/b><\/td>\n<td><b>40000<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b><br \/>\n<\/b><b>Fetched 4 row(s) in 0.59s<\/b><br \/>\n<span style=\"font-weight: 400\">So, here is an example of the Impala union clause. Basically, \u00a0using the UNION clause, we arrange the records in both tables in the order of their id\u2019s and limit their number by 3 using two separate queries and joining these queries.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><b>[quickstart.cloudera:21000] &gt; select * from Students order by id limit 3<\/b><b><br \/>\n<\/b><b> union select * from Users order by id limit 3;<\/b><br \/>\n<span style=\"font-weight: 400\">Hence, we get the following output, on executing the above query.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><b>Query: select * from Students order by id limit 3 union select <\/b><b><br \/>\n<\/b><b> \u00a0\u00a0* from Users order by id limit 3 <\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>Age <\/b><\/td>\n<td><b>Address <\/b><\/td>\n<td><b>Salary<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>monika<\/b><\/td>\n<td><b>25<\/b><\/td>\n<td><b>mumbai<\/b><\/td>\n<td><b>15000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><b>vishal<\/b><\/td>\n<td><b>54<\/b><\/td>\n<td><b>Banglore<\/b><\/td>\n<td><b>55000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>Ankur<\/b><\/td>\n<td><b>34<\/b><\/td>\n<td><b>kolkata<\/b><\/td>\n<td><b>40000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>Shubham<\/b><\/td>\n<td><b>44<\/b><\/td>\n<td><b>Banglore<\/b><\/td>\n<td><b>50000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><b>kajal<\/b><\/td>\n<td><b>27<\/b><b><\/b><\/td>\n<td><b>alirajpur<\/b><b><\/b><\/td>\n<td><b>40000<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>shubham<\/b><\/td>\n<td><b>32<\/b><\/td>\n<td><b>Delhi <\/b><\/td>\n<td><b>20000<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b><br \/>\n<\/b><b>Fetched 6 row(s) in 3.11s<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400\">As a result, we have seen the whole concept of Impala UNION Clause. Still, if any doubt occurs, feel free to ask in the comment section.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While it comes to combine the results of two queries in Impala, we use Impala UNION Clause. There is much more to learn about Impala UNION Clause. So, let\u2019s learn about it from this&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":35013,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[6573,16633,16632,16634],"class_list":["post-12509","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-impala","tag-impala-union-clause","tag-impala-union-clause-example","tag-union-clause-in-impala","tag-use-of-impala-union-clause"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Introduction to Impala UNION Clause with Example - DataFlair<\/title>\n<meta name=\"description\" content=\"If you want to learn about Impala UNION Clause follow this article.It includes its syntax, type as well as its example, to understand it well.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/impala-union-clause\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Impala UNION Clause with Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"If you want to learn about Impala UNION Clause follow this article.It includes its syntax, type as well as its example, to understand it well.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/impala-union-clause\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-10T05:12:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:41:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to Impala UNION Clause with Example - DataFlair","description":"If you want to learn about Impala UNION Clause follow this article.It includes its syntax, type as well as its example, to understand it well.","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:\/\/data-flair.training\/blogs\/impala-union-clause\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to Impala UNION Clause with Example - DataFlair","og_description":"If you want to learn about Impala UNION Clause follow this article.It includes its syntax, type as well as its example, to understand it well.","og_url":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-10T05:12:36+00:00","article_modified_time":"2021-05-09T07:41:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Introduction to Impala UNION Clause with Example","datePublished":"2018-04-10T05:12:36+00:00","dateModified":"2021-05-09T07:41:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/"},"wordCount":492,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg","keywords":["Impala UNION clause","Impala Union Clause example","UNION Clause in Impala","Use of Impala Union Clause"],"articleSection":["Impala Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/impala-union-clause\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/","url":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/","name":"Introduction to Impala UNION Clause with Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg","datePublished":"2018-04-10T05:12:36+00:00","dateModified":"2021-05-09T07:41:01+00:00","description":"If you want to learn about Impala UNION Clause follow this article.It includes its syntax, type as well as its example, to understand it well.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/impala-union-clause\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Impala-UNION-clause-01-1.jpg","width":1200,"height":628,"caption":"Introduction to Impala UNION Clause with Example"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/impala-union-clause\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Impala Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/impala\/"},{"@type":"ListItem","position":3,"name":"Introduction to Impala UNION Clause with Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=12509"}],"version-history":[{"count":1,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12509\/revisions"}],"predecessor-version":[{"id":94037,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12509\/revisions\/94037"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/35013"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=12509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=12509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=12509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}