{"id":350,"date":"2018-05-01T20:06:21","date_gmt":"2018-05-01T13:06:21","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=350"},"modified":"2021-11-06T12:11:07","modified_gmt":"2021-11-06T05:11:07","slug":"sql-server-union","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/","title":{"rendered":"SQL Server UNION"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>UNION<\/code> to combine the results of two or more queries into a single result set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-server-union-operator'>Introduction to SQL Server UNION operator <a href=\"#introduction-to-sql-server-union-operator\" class=\"anchor\" id=\"introduction-to-sql-server-union-operator\" title=\"Anchor for Introduction to SQL Server &lt;code&gt;UNION&lt;\/code&gt; operator\">#<\/a><\/h2>\n\n\n\n<p>SQL Server <code>UNION<\/code> is one of the\u00a0set operations that allow you to combine results of two <code>SELECT<\/code> statements into a single result set which includes all the rows that belong to the <code>SELECT<\/code> statements in the union.<\/p>\n\n\n\n<p>The following illustrates the syntax of the SQL Server <code>UNION<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">query_1\nUNION\nquery_2\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following are requirements for the queries in the syntax above:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The number and the order of the columns must be the same in both queries.<\/li><li>The data types of the corresponding columns must be the same or compatible.<\/li><\/ul>\n\n\n\n<p>The following Venn diagram illustrates how the result set of the T1 table unions with the&nbsp;result set of the T2 table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"175\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram-300x175.png\" alt=\"SQL Server UNION Venn Diagram\" class=\"wp-image-357\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram-300x175.png 300w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram.png 387w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='union-vs-union-all'>UNION vs. UNION ALL <a href=\"#union-vs-union-all\" class=\"anchor\" id=\"union-vs-union-all\" title=\"Anchor for &lt;code&gt;UNION&lt;\/code&gt; vs. &lt;code&gt;UNION ALL&lt;\/code&gt;\">#<\/a><\/h3>\n\n\n\n<p>By default, the <code>UNION<\/code>\u00a0operator removes all duplicate rows from the result sets. However, if you want to retain the duplicate rows, you need to specify the <code>ALL<\/code> keyword is explicitly as shown below:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">query_1\nUNION ALL\nquery_2\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In other words, the&nbsp;<code>UNION<\/code>&nbsp; operator removes the duplicate rows while the <code>UNION ALL<\/code>&nbsp;operator includes the duplicate rows in the final result set.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='union-vs-join'>UNION vs. JOIN <a href=\"#union-vs-join\" class=\"anchor\" id=\"union-vs-join\" title=\"Anchor for &lt;code&gt;UNION&lt;\/code&gt; vs. &lt;code&gt;JOIN&lt;\/code&gt;\">#<\/a><\/h3>\n\n\n\n<p>The join such as <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-inner-join\/\">INNER JOIN<\/a><\/code> or <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-left-join\/\">LEFT JOIN<\/a><\/code> combines <strong>columns<\/strong> from two tables while the <code>UNION<\/code> combines&nbsp;<strong>rows<\/strong> from two queries.<\/p>\n\n\n\n<p>In other words, join appends the result sets horizontally while union appends the result set vertically.<\/p>\n\n\n\n<p>The following picture illustrates the main difference between <code>UNION<\/code> and <code>JOIN<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"489\" height=\"286\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-vs-JOIN.png\" alt=\"SQL Server UNION vs JOIN\" class=\"wp-image-354\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-vs-JOIN.png 489w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-vs-JOIN-300x175.png 300w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-union-examples'>SQL Server UNION examples <a href=\"#sql-server-union-examples\" class=\"anchor\" id=\"sql-server-union-examples\" title=\"Anchor for SQL Server &lt;code&gt;UNION&lt;\/code&gt; examples\">#<\/a><\/h2>\n\n\n\n<p>See the following <code>staffs<\/code> and <code>customers<\/code> tables from the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/\">sample database<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"206\" height=\"219\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/staffs.png\" alt=\"\" class=\"wp-image-149\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"181\" height=\"231\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png\" alt=\"\" class=\"wp-image-158\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='union-and-union-all-examples'>UNION and UNION ALL examples <a href=\"#union-and-union-all-examples\" class=\"anchor\" id=\"union-and-union-all-examples\" title=\"Anchor for &lt;code&gt;UNION&lt;\/code&gt; and &lt;code&gt;UNION ALL&lt;\/code&gt; examples\">#<\/a><\/h3>\n\n\n\n<p>The following example combines names of staff and customers into a single list:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.staffs\n<span class=\"hljs-keyword\">UNION<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.customers;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"143\" height=\"248\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-example.png\" alt=\"SQL Server UNION example\" class=\"wp-image-353\"\/><\/figure>\n\n\n\n<p>It returns 1,454 rows.<\/p>\n\n\n\n<p>The&nbsp;<code>staffs<\/code> table has 10 rows and the customers table has 1,445 rows as shown in the following queries:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    <span class=\"hljs-keyword\">COUNT<\/span> (*)\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.staffs;\n<span class=\"hljs-comment\">-- 10       <\/span>\n\n<span class=\"hljs-keyword\">SELECT<\/span>\n    <span class=\"hljs-keyword\">COUNT<\/span> (*)\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.customers;\n<span class=\"hljs-comment\">-- 1454<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Because the result set of the union returns only 1,454 rows, it means that one duplicate row was removed.<\/p>\n\n\n\n<p>To include the duplicate row, you use the <code>UNION ALL<\/code> as shown in the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.staffs\n<span class=\"hljs-keyword\">UNION<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.customers;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The query returns 1,455 rows as expected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='union-and-order-by-example'>UNION and ORDER BY example <a href=\"#union-and-order-by-example\" class=\"anchor\" id=\"union-and-order-by-example\" title=\"Anchor for &lt;code&gt;UNION&lt;\/code&gt; and &lt;code&gt;ORDER BY&lt;\/code&gt; example\">#<\/a><\/h3>\n\n\n\n<p>To sort the result set returned by the <code>UNION<\/code>&nbsp;operator, you place the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-order-by\/\">ORDER BY<\/a><\/code> clause in the last query as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    select_list\n<span class=\"hljs-keyword\">FROM<\/span>\n    table_1\n<span class=\"hljs-keyword\">UNION<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span>\n    select_list\n<span class=\"hljs-keyword\">FROM<\/span>\n    table_2\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    order_list;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, to sort the first names and last names of customers and staff, you use the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.staffs\n<span class=\"hljs-keyword\">UNION<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span>\n    first_name,\n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    sales.customers\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    first_name,\n    last_name;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"139\" height=\"249\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-ALL-example.png\" alt=\"SQL Server UNION ALL example\" class=\"wp-image-355\"\/><\/figure>\n\n\n\n<p>In this tutorial, you have learned how to use the SQL Server <code>UNION<\/code> to combine rows from multiple queries into a single result set.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"350\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/\"\n\t\t\t\tdata-post-title=\"SQL Server UNION\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"350\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/\"\n\t\t\t\tdata-post-title=\"SQL Server UNION\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use the SQL Server UNION to combine the results of two or more queries into a single result set.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":100,"menu_order":29,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-350","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Server UNION: The Ultimate Guide<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.\" \/>\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.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server UNION: The Ultimate Guide\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-06T05:11:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram-300x175.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/\",\"name\":\"SQL Server UNION: The Ultimate Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-UNION-Venn-Diagram-300x175.png\",\"datePublished\":\"2018-05-01T13:06:21+00:00\",\"dateModified\":\"2021-11-06T05:11:07+00:00\",\"description\":\"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-UNION-Venn-Diagram.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-UNION-Venn-Diagram.png\",\"width\":387,\"height\":226,\"caption\":\"SQL Server UNION Venn Diagram\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-union\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Basics\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server UNION\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server UNION: The Ultimate Guide","description":"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.","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.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server UNION: The Ultimate Guide","og_description":"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2021-11-06T05:11:07+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram-300x175.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/","name":"SQL Server UNION: The Ultimate Guide","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram-300x175.png","datePublished":"2018-05-01T13:06:21+00:00","dateModified":"2021-11-06T05:11:07+00:00","description":"This tutorial shows you how to use the SQL Server UNION to combines rows from two or more queries into a single result.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-UNION-Venn-Diagram.png","width":387,"height":226,"caption":"SQL Server UNION Venn Diagram"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-union\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Basics","item":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/"},{"@type":"ListItem","position":3,"name":"SQL Server UNION"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=350"}],"version-history":[{"count":2,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/350\/revisions"}],"predecessor-version":[{"id":2895,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/350\/revisions\/2895"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/100"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}