1 00:00:01,140 --> 00:00:03,950 In our last video, we learned about unions. 2 00:00:03,950 --> 00:00:06,630 In this video we're gonna take a look at union all. 3 00:00:07,670 --> 00:00:11,810 This is very similar to union but there is one key difference. 4 00:00:11,810 --> 00:00:17,730 The union all will return all of us from each select, even if there are duplicates. 5 00:00:17,730 --> 00:00:23,440 As we saw previously, the union operates a will return a distinct list of results. 6 00:00:23,440 --> 00:00:27,830 In other words, if the row exists in both subsets of the union, 7 00:00:27,830 --> 00:00:30,490 the result will only contain one row. 8 00:00:30,490 --> 00:00:33,280 Here we see two lists of colors union together. 9 00:00:33,280 --> 00:00:37,100 The colors blue and purple exist in both lists. 10 00:00:37,100 --> 00:00:43,230 But what we perform a union, the result set contains only one instance of each. 11 00:00:43,230 --> 00:00:45,340 With the union all operator, 12 00:00:45,340 --> 00:00:50,720 the result set will display the duplicates instead of eliminating them. 13 00:00:50,720 --> 00:00:54,020 Let's take a look at union all in the database. 14 00:00:54,020 --> 00:00:59,480 First let's remind ourselves of what the union of make and foreign make look like. 15 00:00:59,480 --> 00:01:00,961 Now let's run that as a union all. 16 00:01:06,622 --> 00:01:10,790 It's kind of hard to tell how many duplicates there are and how many aren't. 17 00:01:10,790 --> 00:01:13,714 Let's order the results and it should be a little more clear. 18 00:01:19,798 --> 00:01:25,701 Now we can see pretty clearly BMW Honda, 19 00:01:25,701 --> 00:01:30,389 Kia and Toyota are duplicated to 20 00:01:30,389 --> 00:01:35,771 recap You write a union all statement 21 00:01:35,771 --> 00:01:40,960 first by writing a sequel query. 22 00:01:40,960 --> 00:01:44,670 Then the keywords union all and then your second query. 23 00:01:44,670 --> 00:01:49,020 Unions require the number of columns in your data set to be the same for 24 00:01:49,020 --> 00:01:51,060 your first and second queries.