All language subtitles for 027 Merging Queries_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,000 --> 00:00:02,000 Instructor: All right, up next we have Merging Queries. 2 00:00:02,000 --> 00:00:04,000 So you'll see the Merge Query options here 3 00:00:04,000 --> 00:00:06,000 in the Home tab of the Query Editor. 4 00:00:06,000 --> 00:00:08,000 And when you click on that button, 5 00:00:08,000 --> 00:00:11,000 it'll open up a dialogue box like this, 6 00:00:11,000 --> 00:00:13,000 where you can select two tables with matching columns 7 00:00:13,000 --> 00:00:16,000 in order to create a merged table. 8 00:00:16,000 --> 00:00:19,000 And basically, this works just like a lookup in Excel. 9 00:00:19,000 --> 00:00:21,000 You're joining information from two different tables 10 00:00:21,000 --> 00:00:24,000 based on some common column or key. 11 00:00:24,000 --> 00:00:26,000 So in this example that we're looking at here, 12 00:00:26,000 --> 00:00:28,000 we're merging a table called Sales Data 13 00:00:28,000 --> 00:00:31,000 with another table called Product Lookup, 14 00:00:31,000 --> 00:00:34,000 both of which contain a matching product key column. 15 00:00:34,000 --> 00:00:36,000 So essentially, what we'll be doing here 16 00:00:36,000 --> 00:00:38,000 is grabbing information or attributes 17 00:00:38,000 --> 00:00:41,000 about those product keys from the Product Lookup table 18 00:00:41,000 --> 00:00:45,000 and pulling them in or embedding them into the Sales table 19 00:00:45,000 --> 00:00:48,000 by matching them to the associated product keys. 20 00:00:48,000 --> 00:00:49,000 So my trick for remembering this 21 00:00:49,000 --> 00:00:53,000 is that merging adds columns to an existing table. 22 00:00:53,000 --> 00:00:55,000 So you're not adding any rows, 23 00:00:55,000 --> 00:00:58,000 you're pulling in more information 24 00:00:58,000 --> 00:01:01,000 and making your table wider by adding columns. 25 00:01:01,000 --> 00:01:03,000 So very important point here, 26 00:01:03,000 --> 00:01:06,000 just because you can merge tables 27 00:01:06,000 --> 00:01:08,000 and because it's an interesting tool to use, 28 00:01:08,000 --> 00:01:10,000 that doesn't mean that you should. 29 00:01:10,000 --> 00:01:13,000 In fact, it's generally better to keep tables separate 30 00:01:13,000 --> 00:01:17,000 and define relationships between them within the data model, 31 00:01:17,000 --> 00:01:18,000 and again, more on that later, 32 00:01:18,000 --> 00:01:21,000 but keep that idea in the back of your head, 33 00:01:21,000 --> 00:01:22,000 that you can merge queries like this 34 00:01:22,000 --> 00:01:25,000 but it's always not the most efficient solution. 35 00:01:25,000 --> 00:01:28,000 So why don't we go and jump into the Query Editor, 36 00:01:28,000 --> 00:01:29,000 and I'll show you 37 00:01:29,000 --> 00:01:31,000 what one of these merges actually looks like. 38 00:01:33,000 --> 00:01:35,000 Okay, so I'm in the Query Editor 39 00:01:35,000 --> 00:01:37,000 of my AdventureWorks Report, 40 00:01:37,000 --> 00:01:39,000 and to demo the idea of merging, 41 00:01:39,000 --> 00:01:41,000 let's say that we wanna look at our sales data, 42 00:01:41,000 --> 00:01:44,000 which has our order dates and order numbers, 43 00:01:44,000 --> 00:01:47,000 our product key, customer key, territory key, 44 00:01:47,000 --> 00:01:50,000 order line items, quantities, right? 45 00:01:50,000 --> 00:01:53,000 We've got all of these attributes related to our sales. 46 00:01:53,000 --> 00:01:55,000 And let's say we wanna pull in a little information 47 00:01:55,000 --> 00:01:58,000 about these products right here into the Sales table 48 00:01:58,000 --> 00:02:02,000 without having to go over into the Product Lookup, 49 00:02:02,000 --> 00:02:04,000 find the associated product key, 50 00:02:04,000 --> 00:02:07,000 and then look at the information here, right? 51 00:02:07,000 --> 00:02:10,000 Let's just say we want all of that information accessible 52 00:02:10,000 --> 00:02:11,000 in one place. 53 00:02:11,000 --> 00:02:13,000 So this is a opportunity 54 00:02:13,000 --> 00:02:15,000 that we could use a tool like Merge. 55 00:02:15,000 --> 00:02:18,000 So I'm gonna start with the Sales Data here, 56 00:02:18,000 --> 00:02:19,000 and from my Home tab, 57 00:02:19,000 --> 00:02:21,000 and all the way over on the right here, 58 00:02:21,000 --> 00:02:24,000 you're gonna see options for Merge and Append, 59 00:02:24,000 --> 00:02:26,000 and we'll talk about Append next. 60 00:02:26,000 --> 00:02:29,000 But with Merge, I can do it in a couple of different ways. 61 00:02:29,000 --> 00:02:32,000 I can either Merge Queries or Merge Queries as New. 62 00:02:32,000 --> 00:02:35,000 And if I just simply use the Merge Queries option, 63 00:02:35,000 --> 00:02:39,000 it will preserve the exact tables that I have in place now 64 00:02:39,000 --> 00:02:41,000 and it will just add the merged columns 65 00:02:41,000 --> 00:02:45,000 into my existing Sales Data 2022 table. 66 00:02:45,000 --> 00:02:47,000 If I choose the second option, 67 00:02:47,000 --> 00:02:49,000 it's gonna create a brand new merged table 68 00:02:49,000 --> 00:02:51,000 that contains the merged results 69 00:02:51,000 --> 00:02:55,000 while maintaining my original component tables as well. 70 00:02:55,000 --> 00:02:58,000 So I really don't want or need this option at this point 71 00:02:58,000 --> 00:03:00,000 so we're gonna click on Merge Queries. 72 00:03:00,000 --> 00:03:03,000 So what we have here is we have our first table, right? 73 00:03:03,000 --> 00:03:06,000 We had selected the Sales Data 2022 table. 74 00:03:06,000 --> 00:03:08,000 So this is the first table that shows up 75 00:03:08,000 --> 00:03:11,000 in our Merge Queries option, right? 76 00:03:11,000 --> 00:03:15,000 We can see all of the columns contained within that table. 77 00:03:15,000 --> 00:03:18,000 And then below that we have this dropdown menu, 78 00:03:18,000 --> 00:03:20,000 and this allows us to access all of the other queries 79 00:03:20,000 --> 00:03:24,000 that have been added into the Query Editor. 80 00:03:24,000 --> 00:03:25,000 And again, we wanna grab detail 81 00:03:25,000 --> 00:03:28,000 from the Product Lookup table, right? 82 00:03:28,000 --> 00:03:30,000 And so then again here we get this preview 83 00:03:30,000 --> 00:03:32,000 of all of the columns contained 84 00:03:32,000 --> 00:03:34,000 within our Product Lookup table. 85 00:03:34,000 --> 00:03:39,000 And the only columns that these two tables have in common 86 00:03:39,000 --> 00:03:40,000 is Product Key. 87 00:03:40,000 --> 00:03:43,000 So if I select Product Key and Product Key, 88 00:03:43,000 --> 00:03:47,000 Power BI goes through, you can see down at the bottom here, 89 00:03:47,000 --> 00:03:52,000 it says, "The selection matches 29,481 of 29,481 rows 90 00:03:54,000 --> 00:03:55,000 from the first table." 91 00:03:55,000 --> 00:03:58,000 So it's an exact match from product to product. 92 00:03:58,000 --> 00:04:00,000 The other thing to pay attention to here 93 00:04:00,000 --> 00:04:03,000 but not something that we necessarily have to worry about 94 00:04:03,000 --> 00:04:04,000 is the join type, right? 95 00:04:04,000 --> 00:04:07,000 So by default, this join is a left outer. 96 00:04:07,000 --> 00:04:09,000 And what this is basically saying 97 00:04:09,000 --> 00:04:11,000 is take all of the product keys 98 00:04:11,000 --> 00:04:13,000 that exist on my first table, 99 00:04:13,000 --> 00:04:16,000 this Sales Data 2022 table, 100 00:04:16,000 --> 00:04:19,000 and grab any rows that you find a match for 101 00:04:19,000 --> 00:04:22,000 in my second table, this Product Lookup table. 102 00:04:22,000 --> 00:04:25,000 And for our purposes, this is gonna do the trick. 103 00:04:25,000 --> 00:04:28,000 So everything looks good here, we'll click OK. 104 00:04:29,000 --> 00:04:31,000 And so you see what happens here, 105 00:04:31,000 --> 00:04:33,000 we've added a new column 106 00:04:33,000 --> 00:04:35,000 but the column looks kind of funny. 107 00:04:35,000 --> 00:04:39,000 It says, "Table," and it's formatted with these links. 108 00:04:39,000 --> 00:04:40,000 All right, so from here, 109 00:04:40,000 --> 00:04:43,000 we actually have one extra step that we need to take, 110 00:04:43,000 --> 00:04:46,000 and it's to click this Double Arrow button here 111 00:04:46,000 --> 00:04:50,000 to expand the table and all of the contents within it. 112 00:04:50,000 --> 00:04:52,000 Right, so by default, all of the columns 113 00:04:52,000 --> 00:04:55,000 from the table that we wanna join are selected, 114 00:04:55,000 --> 00:04:57,000 and if we were to press OK here, 115 00:04:57,000 --> 00:05:00,000 this would add all of these columns as part of the merge. 116 00:05:00,000 --> 00:05:03,000 And honestly, that's not really what we want. 117 00:05:03,000 --> 00:05:03,000 So we wanna go through 118 00:05:03,000 --> 00:05:06,000 and select the columns that we actually wanna see. 119 00:05:06,000 --> 00:05:08,000 So let's start off, we'll select Product Key. 120 00:05:08,000 --> 00:05:11,000 This will give us a way to kinda compare results. 121 00:05:11,000 --> 00:05:16,000 And then let's say we want Product Name and Product Color. 122 00:05:16,000 --> 00:05:18,000 Our last checkbox here, 123 00:05:18,000 --> 00:05:20,000 Use Original Column Names as the Prefix, 124 00:05:20,000 --> 00:05:22,000 if I leave this selected, 125 00:05:22,000 --> 00:05:25,000 it's gonna create a prefix for every column name 126 00:05:25,000 --> 00:05:27,000 with the name of the product table, right? 127 00:05:27,000 --> 00:05:29,000 And we'll see what that looks like in a minute. 128 00:05:29,000 --> 00:05:32,000 I'll just leave this selected for the sake of this example. 129 00:05:32,000 --> 00:05:33,000 So we click OK. 130 00:05:35,000 --> 00:05:39,000 And now we've expanded the Product Lookup table. 131 00:05:39,000 --> 00:05:40,000 And now we've got this new information 132 00:05:40,000 --> 00:05:42,000 that didn't exist in the sales table 133 00:05:42,000 --> 00:05:44,000 up until this point, right? 134 00:05:44,000 --> 00:05:47,000 We've got Product Name and Product Color detail, 135 00:05:47,000 --> 00:05:50,000 and it's populated for every single row of the table, 136 00:05:50,000 --> 00:05:54,000 just like it would if we were using an Excel Lookup, right? 137 00:05:54,000 --> 00:05:57,000 So we can scroll over to the left here, right? 138 00:05:57,000 --> 00:06:02,000 And you can see we've got Product Key 529, 529, 214. 139 00:06:02,000 --> 00:06:03,000 Scroll back over. 140 00:06:04,000 --> 00:06:07,000 Right, we've got 529, 529, 214, right? 141 00:06:07,000 --> 00:06:11,000 So we can see that we've got all of this new data added in 142 00:06:11,000 --> 00:06:13,000 for every record of the table. 143 00:06:13,000 --> 00:06:15,000 And, like I hinted at earlier, 144 00:06:15,000 --> 00:06:18,000 just because we can do things like this 145 00:06:18,000 --> 00:06:20,000 and merge tables together 146 00:06:20,000 --> 00:06:22,000 doesn't mean that we always should. 147 00:06:22,000 --> 00:06:25,000 In fact, merging information in the way that we just did 148 00:06:25,000 --> 00:06:28,000 actually creates a lot of duplicative and redundant data, 149 00:06:28,000 --> 00:06:32,000 which can be avoided entirely by using table relationships. 150 00:06:32,000 --> 00:06:33,000 Again, we're getting there soon. 151 00:06:33,000 --> 00:06:36,000 We'll cover relationships in the next section. 152 00:06:36,000 --> 00:06:39,000 But for now, let's go ahead and we'll delete that merge. 153 00:06:39,000 --> 00:06:41,000 And now we are back to where we started. 154 00:06:41,000 --> 00:06:44,000 So there's a quick demo for you on how to merge queries. 12484

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.