-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoining-data-in-sql 2.html
640 lines (598 loc) · 63.7 KB
/
joining-data-in-sql 2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>11 Joining Data in SQL | R Programming Guidebook Project</title>
<meta name="description" content="11 Joining Data in SQL | R Programming Guidebook Project" />
<meta name="generator" content="bookdown 0.24 and GitBook 2.6.7" />
<meta property="og:title" content="11 Joining Data in SQL | R Programming Guidebook Project" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="11 Joining Data in SQL | R Programming Guidebook Project" />
<meta name="author" content="Alec Nguyen" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="introduction-to-sql.html"/>
<link rel="next" href="web-scraping-in-r.html"/>
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>About</a></li>
<li class="part"><span><b>I DataCamp</b></span></li>
<li class="chapter" data-level="1" data-path="introduction-to-r.html"><a href="introduction-to-r.html"><i class="fa fa-check"></i><b>1</b> Introduction to R</a>
<ul>
<li class="chapter" data-level="1.1" data-path="introduction-to-r.html"><a href="introduction-to-r.html#intro-to-basics"><i class="fa fa-check"></i><b>1.1</b> Intro to basics</a></li>
<li class="chapter" data-level="1.2" data-path="introduction-to-r.html"><a href="introduction-to-r.html#vectors"><i class="fa fa-check"></i><b>1.2</b> Vectors</a></li>
<li class="chapter" data-level="1.3" data-path="introduction-to-r.html"><a href="introduction-to-r.html#matrices"><i class="fa fa-check"></i><b>1.3</b> Matrices</a></li>
<li class="chapter" data-level="1.4" data-path="introduction-to-r.html"><a href="introduction-to-r.html#factors"><i class="fa fa-check"></i><b>1.4</b> Factors</a></li>
<li class="chapter" data-level="1.5" data-path="introduction-to-r.html"><a href="introduction-to-r.html#data-frames"><i class="fa fa-check"></i><b>1.5</b> Data frames</a></li>
<li class="chapter" data-level="1.6" data-path="introduction-to-r.html"><a href="introduction-to-r.html#lists"><i class="fa fa-check"></i><b>1.6</b> Lists</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="intermediate-r.html"><a href="intermediate-r.html"><i class="fa fa-check"></i><b>2</b> Intermediate R</a>
<ul>
<li class="chapter" data-level="2.1" data-path="intermediate-r.html"><a href="intermediate-r.html#conditionals-and-control-flow"><i class="fa fa-check"></i><b>2.1</b> Conditionals And Control Flow</a></li>
<li class="chapter" data-level="2.2" data-path="intermediate-r.html"><a href="intermediate-r.html#loops"><i class="fa fa-check"></i><b>2.2</b> Loops</a></li>
<li class="chapter" data-level="2.3" data-path="intermediate-r.html"><a href="intermediate-r.html#functions"><i class="fa fa-check"></i><b>2.3</b> Functions</a></li>
<li class="chapter" data-level="2.4" data-path="intermediate-r.html"><a href="intermediate-r.html#the-apply-family"><i class="fa fa-check"></i><b>2.4</b> The apply family</a></li>
<li class="chapter" data-level="2.5" data-path="intermediate-r.html"><a href="intermediate-r.html#utilities"><i class="fa fa-check"></i><b>2.5</b> Utilities</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="intro-to-the-tidyverse.html"><a href="intro-to-the-tidyverse.html"><i class="fa fa-check"></i><b>3</b> Intro to the Tidyverse</a>
<ul>
<li class="chapter" data-level="3.1" data-path="intro-to-the-tidyverse.html"><a href="intro-to-the-tidyverse.html#data-wrangling"><i class="fa fa-check"></i><b>3.1</b> Data wrangling</a></li>
<li class="chapter" data-level="3.2" data-path="intro-to-the-tidyverse.html"><a href="intro-to-the-tidyverse.html#data-visualization"><i class="fa fa-check"></i><b>3.2</b> Data visualization</a></li>
<li class="chapter" data-level="3.3" data-path="intro-to-the-tidyverse.html"><a href="intro-to-the-tidyverse.html#grouping-and-summarizing"><i class="fa fa-check"></i><b>3.3</b> Grouping and summarizing</a></li>
<li class="chapter" data-level="3.4" data-path="intro-to-the-tidyverse.html"><a href="intro-to-the-tidyverse.html#types-of-visualizations"><i class="fa fa-check"></i><b>3.4</b> Types of visualizations</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="intro-to-data-visualization-with-ggplot2.html"><a href="intro-to-data-visualization-with-ggplot2.html"><i class="fa fa-check"></i><b>4</b> Intro to Data Visualization with ggplot2</a>
<ul>
<li class="chapter" data-level="4.1" data-path="intro-to-data-visualization-with-ggplot2.html"><a href="intro-to-data-visualization-with-ggplot2.html#introduction"><i class="fa fa-check"></i><b>4.1</b> Introduction</a></li>
<li class="chapter" data-level="4.2" data-path="intro-to-data-visualization-with-ggplot2.html"><a href="intro-to-data-visualization-with-ggplot2.html#aesthetics"><i class="fa fa-check"></i><b>4.2</b> Aesthetics</a></li>
<li class="chapter" data-level="4.3" data-path="intro-to-data-visualization-with-ggplot2.html"><a href="intro-to-data-visualization-with-ggplot2.html#geometries"><i class="fa fa-check"></i><b>4.3</b> Geometries</a></li>
<li class="chapter" data-level="4.4" data-path="intro-to-data-visualization-with-ggplot2.html"><a href="intro-to-data-visualization-with-ggplot2.html#themes"><i class="fa fa-check"></i><b>4.4</b> Themes</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="working-with-data-in-the-tidyverse.html"><a href="working-with-data-in-the-tidyverse.html"><i class="fa fa-check"></i><b>5</b> Working with Data in the Tidyverse</a>
<ul>
<li class="chapter" data-level="5.1" data-path="working-with-data-in-the-tidyverse.html"><a href="working-with-data-in-the-tidyverse.html#explore-your-data"><i class="fa fa-check"></i><b>5.1</b> Explore your data</a></li>
<li class="chapter" data-level="5.2" data-path="working-with-data-in-the-tidyverse.html"><a href="working-with-data-in-the-tidyverse.html#tame-your-data"><i class="fa fa-check"></i><b>5.2</b> Tame your data</a></li>
<li class="chapter" data-level="5.3" data-path="working-with-data-in-the-tidyverse.html"><a href="working-with-data-in-the-tidyverse.html#tidy-your-data"><i class="fa fa-check"></i><b>5.3</b> Tidy your data</a></li>
<li class="chapter" data-level="5.4" data-path="working-with-data-in-the-tidyverse.html"><a href="working-with-data-in-the-tidyverse.html#transform-your-data"><i class="fa fa-check"></i><b>5.4</b> Transform your data</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="categorical-data-in-the-tidyverse.html"><a href="categorical-data-in-the-tidyverse.html"><i class="fa fa-check"></i><b>6</b> Categorical Data in the Tidyverse</a>
<ul>
<li class="chapter" data-level="6.1" data-path="categorical-data-in-the-tidyverse.html"><a href="categorical-data-in-the-tidyverse.html#introduction-to-factor-variables"><i class="fa fa-check"></i><b>6.1</b> Introduction to Factor Variables</a></li>
<li class="chapter" data-level="6.2" data-path="categorical-data-in-the-tidyverse.html"><a href="categorical-data-in-the-tidyverse.html#manipulating-factor-variables"><i class="fa fa-check"></i><b>6.2</b> Manipulating Factor Variables</a></li>
<li class="chapter" data-level="6.3" data-path="categorical-data-in-the-tidyverse.html"><a href="categorical-data-in-the-tidyverse.html#creating-factor-variables"><i class="fa fa-check"></i><b>6.3</b> Creating Factor Variables</a></li>
<li class="chapter" data-level="6.4" data-path="categorical-data-in-the-tidyverse.html"><a href="categorical-data-in-the-tidyverse.html#case-study-on-flight-etiquette"><i class="fa fa-check"></i><b>6.4</b> Case Study on Flight Etiquette</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="data-manipulation-with-dplyr.html"><a href="data-manipulation-with-dplyr.html"><i class="fa fa-check"></i><b>7</b> Data Manipulation with dplyr</a>
<ul>
<li class="chapter" data-level="7.1" data-path="data-manipulation-with-dplyr.html"><a href="data-manipulation-with-dplyr.html#transforming-data-with-dplyr"><i class="fa fa-check"></i><b>7.1</b> Transforming Data with dplyr</a></li>
<li class="chapter" data-level="7.2" data-path="data-manipulation-with-dplyr.html"><a href="data-manipulation-with-dplyr.html#aggregating-data"><i class="fa fa-check"></i><b>7.2</b> Aggregating Data</a></li>
<li class="chapter" data-level="7.3" data-path="data-manipulation-with-dplyr.html"><a href="data-manipulation-with-dplyr.html#selecting-and-transforming-data"><i class="fa fa-check"></i><b>7.3</b> Selecting and Transforming Data</a></li>
<li class="chapter" data-level="7.4" data-path="data-manipulation-with-dplyr.html"><a href="data-manipulation-with-dplyr.html#case-study-the-babynames-dataset"><i class="fa fa-check"></i><b>7.4</b> Case Study: The babynames Dataset</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="joining-data-with-dplyr.html"><a href="joining-data-with-dplyr.html"><i class="fa fa-check"></i><b>8</b> Joining Data with dplyr</a>
<ul>
<li class="chapter" data-level="8.1" data-path="joining-data-with-dplyr.html"><a href="joining-data-with-dplyr.html#joining-tables"><i class="fa fa-check"></i><b>8.1</b> Joining Tables</a></li>
<li class="chapter" data-level="8.2" data-path="joining-data-with-dplyr.html"><a href="joining-data-with-dplyr.html#left-and-right-joins"><i class="fa fa-check"></i><b>8.2</b> Left and Right Joins</a></li>
<li class="chapter" data-level="8.3" data-path="joining-data-with-dplyr.html"><a href="joining-data-with-dplyr.html#full-semi-and-anti-joins"><i class="fa fa-check"></i><b>8.3</b> Full, Semi, and Anti Joins</a></li>
<li class="chapter" data-level="8.4" data-path="joining-data-with-dplyr.html"><a href="joining-data-with-dplyr.html#case-study-joins-on-stack-overflow-data"><i class="fa fa-check"></i><b>8.4</b> Case Study: Joins on Stack Overflow Data</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="cleaning-data-in-r.html"><a href="cleaning-data-in-r.html"><i class="fa fa-check"></i><b>9</b> Cleaning Data in R</a>
<ul>
<li class="chapter" data-level="9.1" data-path="cleaning-data-in-r.html"><a href="cleaning-data-in-r.html#common-data-problems"><i class="fa fa-check"></i><b>9.1</b> Common Data Problems</a></li>
<li class="chapter" data-level="9.2" data-path="cleaning-data-in-r.html"><a href="cleaning-data-in-r.html#categorical-and-text-data"><i class="fa fa-check"></i><b>9.2</b> Categorical and Text Data</a></li>
<li class="chapter" data-level="9.3" data-path="cleaning-data-in-r.html"><a href="cleaning-data-in-r.html#advanced-data-problems"><i class="fa fa-check"></i><b>9.3</b> Advanced Data Problems</a></li>
<li class="chapter" data-level="9.4" data-path="cleaning-data-in-r.html"><a href="cleaning-data-in-r.html#record-linkage"><i class="fa fa-check"></i><b>9.4</b> Record Linkage</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="introduction-to-sql.html"><a href="introduction-to-sql.html"><i class="fa fa-check"></i><b>10</b> Introduction to SQL</a>
<ul>
<li class="chapter" data-level="10.1" data-path="introduction-to-sql.html"><a href="introduction-to-sql.html#selecting-columns"><i class="fa fa-check"></i><b>10.1</b> Selecting columns</a></li>
<li class="chapter" data-level="10.2" data-path="introduction-to-sql.html"><a href="introduction-to-sql.html#filtering-rows"><i class="fa fa-check"></i><b>10.2</b> Filtering rows</a></li>
<li class="chapter" data-level="10.3" data-path="introduction-to-sql.html"><a href="introduction-to-sql.html#aggregate-functions"><i class="fa fa-check"></i><b>10.3</b> Aggregate Functions</a></li>
<li class="chapter" data-level="10.4" data-path="introduction-to-sql.html"><a href="introduction-to-sql.html#sorting-and-grouping"><i class="fa fa-check"></i><b>10.4</b> Sorting and grouping</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="joining-data-in-sql.html"><a href="joining-data-in-sql.html"><i class="fa fa-check"></i><b>11</b> Joining Data in SQL</a>
<ul>
<li class="chapter" data-level="11.1" data-path="joining-data-in-sql.html"><a href="joining-data-in-sql.html#introduction-to-joins"><i class="fa fa-check"></i><b>11.1</b> Introduction to joins</a></li>
<li class="chapter" data-level="11.2" data-path="joining-data-in-sql.html"><a href="joining-data-in-sql.html#outer-joins-and-cross-joins"><i class="fa fa-check"></i><b>11.2</b> Outer joins and cross joins</a></li>
<li class="chapter" data-level="11.3" data-path="joining-data-in-sql.html"><a href="joining-data-in-sql.html#set-theory-clauses"><i class="fa fa-check"></i><b>11.3</b> Set theory clauses</a></li>
<li class="chapter" data-level="11.4" data-path="joining-data-in-sql.html"><a href="joining-data-in-sql.html#subqueries"><i class="fa fa-check"></i><b>11.4</b> Subqueries</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="web-scraping-in-r.html"><a href="web-scraping-in-r.html"><i class="fa fa-check"></i><b>12</b> Web Scraping in R</a>
<ul>
<li class="chapter" data-level="12.1" data-path="web-scraping-in-r.html"><a href="web-scraping-in-r.html#introduction-to-html-and-web-scraping"><i class="fa fa-check"></i><b>12.1</b> Introduction to HTML and Web Scraping</a></li>
<li class="chapter" data-level="12.2" data-path="web-scraping-in-r.html"><a href="web-scraping-in-r.html#navigation-and-selection-with-css"><i class="fa fa-check"></i><b>12.2</b> Navigation and Selection with CSS</a></li>
<li class="chapter" data-level="12.3" data-path="web-scraping-in-r.html"><a href="web-scraping-in-r.html#advanced-selection-with-xpath"><i class="fa fa-check"></i><b>12.3</b> Advanced Selection with XPATH</a></li>
<li class="chapter" data-level="12.4" data-path="web-scraping-in-r.html"><a href="web-scraping-in-r.html#scraping-best-practices"><i class="fa fa-check"></i><b>12.4</b> Scraping Best Practices</a></li>
</ul></li>
<li class="part"><span><b>II Econometrics</b></span></li>
<li class="chapter" data-level="13" data-path="ch-2---slr.html"><a href="ch-2---slr.html"><i class="fa fa-check"></i><b>13</b> Ch 2 - SLR</a>
<ul>
<li class="chapter" data-level="13.1" data-path="ch-2---slr.html"><a href="ch-2---slr.html#notes"><i class="fa fa-check"></i><b>13.1</b> Notes</a></li>
<li class="chapter" data-level="13.2" data-path="ch-2---slr.html"><a href="ch-2---slr.html#example-2.3-ceo-salary-and-return-on-equity"><i class="fa fa-check"></i><b>13.2</b> Example 2.3: CEO Salary and Return on Equity</a></li>
<li class="chapter" data-level="13.3" data-path="ch-2---slr.html"><a href="ch-2---slr.html#example-2.4-wage-and-education"><i class="fa fa-check"></i><b>13.3</b> Example 2.4: Wage and Education</a></li>
<li class="chapter" data-level="13.4" data-path="ch-2---slr.html"><a href="ch-2---slr.html#example-2.5-voting-outcomes-and-campaign-expenditures"><i class="fa fa-check"></i><b>13.4</b> Example 2.5: Voting Outcomes and Campaign Expenditures</a></li>
<li class="chapter" data-level="13.5" data-path="ch-2---slr.html"><a href="ch-2---slr.html#example-of-fitted-values-haty"><i class="fa fa-check"></i><b>13.5</b> Example of Fitted Values (<span class="math inline">\(\hat{y}\)</span>)</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html"><i class="fa fa-check"></i><b>14</b> Ch 3 - MLR</a>
<ul>
<li class="chapter" data-level="14.1" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#data"><i class="fa fa-check"></i><b>14.1</b> Data</a>
<ul>
<li class="chapter" data-level="14.1.1" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#summary-statistics"><i class="fa fa-check"></i><b>14.1.1</b> Summary Statistics</a></li>
</ul></li>
<li class="chapter" data-level="14.2" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#regression-model-comparisons"><i class="fa fa-check"></i><b>14.2</b> Regression model comparisons</a></li>
<li class="chapter" data-level="14.3" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#adjusted-r-squared"><i class="fa fa-check"></i><b>14.3</b> Adjusted R-Squared</a></li>
<li class="chapter" data-level="14.4" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#multicollinearity"><i class="fa fa-check"></i><b>14.4</b> Multicollinearity</a>
<ul>
<li class="chapter" data-level="14.4.1" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#variance-inflation-factor-vif"><i class="fa fa-check"></i><b>14.4.1</b> Variance Inflation Factor (VIF)</a></li>
<li class="chapter" data-level="14.4.2" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#joint-hypotheses-test"><i class="fa fa-check"></i><b>14.4.2</b> Joint hypotheses test</a></li>
</ul></li>
<li class="chapter" data-level="14.5" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#testing-linear-combinations-of-parameters"><i class="fa fa-check"></i><b>14.5</b> Testing linear combinations of parameters</a></li>
<li class="chapter" data-level="14.6" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#a-note-on-presentation"><i class="fa fa-check"></i><b>14.6</b> A note on presentation</a></li>
<li class="chapter" data-level="14.7" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#log-transformations"><i class="fa fa-check"></i><b>14.7</b> Log transformations</a>
<ul>
<li class="chapter" data-level="14.7.1" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#histograms"><i class="fa fa-check"></i><b>14.7.1</b> Histograms</a></li>
<li class="chapter" data-level="14.7.2" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#scatter-plots"><i class="fa fa-check"></i><b>14.7.2</b> Scatter plots</a></li>
<li class="chapter" data-level="14.7.3" data-path="ch-3---mlr.html"><a href="ch-3---mlr.html#regression-models-with-levels-and-logs"><i class="fa fa-check"></i><b>14.7.3</b> Regression models with levels and logs</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="15" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html"><i class="fa fa-check"></i><b>15</b> Dummy Variables Part 1</a>
<ul>
<li class="chapter" data-level="15.1" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#obtain-and-prepare-data"><i class="fa fa-check"></i><b>15.1</b> Obtain and prepare data</a></li>
<li class="chapter" data-level="15.2" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#define-dummy-variables"><i class="fa fa-check"></i><b>15.2</b> Define dummy variables</a>
<ul>
<li class="chapter" data-level="15.2.1" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#alpha-model"><i class="fa fa-check"></i><b>15.2.1</b> Alpha Model</a></li>
<li class="chapter" data-level="15.2.2" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#beta-model"><i class="fa fa-check"></i><b>15.2.2</b> Beta Model</a></li>
</ul></li>
<li class="chapter" data-level="15.3" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#compare-the-regressions-side-by-side"><i class="fa fa-check"></i><b>15.3</b> Compare the regressions side-by-side</a></li>
<li class="chapter" data-level="15.4" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#compare-the-predictions-of-each-model"><i class="fa fa-check"></i><b>15.4</b> Compare the predictions of each model</a>
<ul>
<li class="chapter" data-level="15.4.1" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#group-averages"><i class="fa fa-check"></i><b>15.4.1</b> Group averages</a></li>
<li class="chapter" data-level="15.4.2" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#causal-estimates"><i class="fa fa-check"></i><b>15.4.2</b> Causal estimates?</a></li>
<li class="chapter" data-level="15.4.3" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#what-about-age"><i class="fa fa-check"></i><b>15.4.3</b> What about age?</a></li>
<li class="chapter" data-level="15.4.4" data-path="dummy-variables-part-1.html"><a href="dummy-variables-part-1.html#what-about-sex"><i class="fa fa-check"></i><b>15.4.4</b> What about sex?</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="16" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html"><i class="fa fa-check"></i><b>16</b> Dummy Variables Part 2</a>
<ul>
<li class="chapter" data-level="16.1" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html#size-only"><i class="fa fa-check"></i><b>16.1</b> Size only</a></li>
<li class="chapter" data-level="16.2" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html#number-of-bathrooms-and-size"><i class="fa fa-check"></i><b>16.2</b> Number of bathrooms and size</a></li>
<li class="chapter" data-level="16.3" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html#slope-dummy"><i class="fa fa-check"></i><b>16.3</b> Slope dummy</a></li>
<li class="chapter" data-level="16.4" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html#intercept-and-slope-dummies"><i class="fa fa-check"></i><b>16.4</b> Intercept and slope dummies</a></li>
<li class="chapter" data-level="16.5" data-path="dummy-variables-part-2.html"><a href="dummy-variables-part-2.html#models-with-the-number-of-bedrooms"><i class="fa fa-check"></i><b>16.5</b> Models with the number of bedrooms</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="fixed-effects.html"><a href="fixed-effects.html"><i class="fa fa-check"></i><b>17</b> Fixed Effects</a>
<ul>
<li class="chapter" data-level="17.1" data-path="fixed-effects.html"><a href="fixed-effects.html#variables"><i class="fa fa-check"></i><b>17.1</b> Variables</a></li>
<li class="chapter" data-level="17.2" data-path="fixed-effects.html"><a href="fixed-effects.html#ols"><i class="fa fa-check"></i><b>17.2</b> OLS</a></li>
<li class="chapter" data-level="17.3" data-path="fixed-effects.html"><a href="fixed-effects.html#country-fixed-effects"><i class="fa fa-check"></i><b>17.3</b> Country Fixed Effects</a></li>
<li class="chapter" data-level="17.4" data-path="fixed-effects.html"><a href="fixed-effects.html#year-fixed-effects"><i class="fa fa-check"></i><b>17.4</b> Year Fixed Effects</a></li>
<li class="chapter" data-level="17.5" data-path="fixed-effects.html"><a href="fixed-effects.html#country-and-year-fixed-effects"><i class="fa fa-check"></i><b>17.5</b> Country and Year Fixed Effects</a></li>
<li class="chapter" data-level="17.6" data-path="fixed-effects.html"><a href="fixed-effects.html#comparison-of-all-models"><i class="fa fa-check"></i><b>17.6</b> Comparison of all models</a>
<ul>
<li class="chapter" data-level="17.6.1" data-path="fixed-effects.html"><a href="fixed-effects.html#within-transformation"><i class="fa fa-check"></i><b>17.6.1</b> Within Transformation</a></li>
<li class="chapter" data-level="17.6.2" data-path="fixed-effects.html"><a href="fixed-effects.html#plm-package"><i class="fa fa-check"></i><b>17.6.2</b> PLM Package</a></li>
<li class="chapter" data-level="17.6.3" data-path="fixed-effects.html"><a href="fixed-effects.html#dummy-variables"><i class="fa fa-check"></i><b>17.6.3</b> Dummy Variables</a></li>
</ul></li>
<li class="chapter" data-level="17.7" data-path="fixed-effects.html"><a href="fixed-effects.html#data-summary-by-country"><i class="fa fa-check"></i><b>17.7</b> Data Summary by Country</a>
<ul>
<li class="chapter" data-level="17.7.1" data-path="fixed-effects.html"><a href="fixed-effects.html#average-values-for-each-country"><i class="fa fa-check"></i><b>17.7.1</b> Average Values for Each Country</a></li>
<li class="chapter" data-level="17.7.2" data-path="fixed-effects.html"><a href="fixed-effects.html#variable-specific-values-and-within-transformation-for-each-country"><i class="fa fa-check"></i><b>17.7.2</b> Variable-Specific Values and Within Transformation for Each Country</a></li>
<li class="chapter" data-level="17.7.3" data-path="fixed-effects.html"><a href="fixed-effects.html#life-expectancy"><i class="fa fa-check"></i><b>17.7.3</b> Life expectancy</a></li>
<li class="chapter" data-level="17.7.4" data-path="fixed-effects.html"><a href="fixed-effects.html#gdp-per-capita"><i class="fa fa-check"></i><b>17.7.4</b> GDP per capita</a></li>
<li class="chapter" data-level="17.7.5" data-path="fixed-effects.html"><a href="fixed-effects.html#population"><i class="fa fa-check"></i><b>17.7.5</b> Population</a></li>
<li class="chapter" data-level="17.7.6" data-path="fixed-effects.html"><a href="fixed-effects.html#percent-female"><i class="fa fa-check"></i><b>17.7.6</b> Percent female</a></li>
<li class="chapter" data-level="17.7.7" data-path="fixed-effects.html"><a href="fixed-effects.html#percent-rural"><i class="fa fa-check"></i><b>17.7.7</b> Percent rural</a></li>
</ul></li>
<li class="chapter" data-level="17.8" data-path="fixed-effects.html"><a href="fixed-effects.html#bookdown-style-note"><i class="fa fa-check"></i><b>17.8</b> Bookdown Style Note</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="difference-in-differences.html"><a href="difference-in-differences.html"><i class="fa fa-check"></i><b>18</b> Difference-in-Differences</a>
<ul>
<li class="chapter" data-level="18.1" data-path="difference-in-differences.html"><a href="difference-in-differences.html#data-1"><i class="fa fa-check"></i><b>18.1</b> Data</a></li>
<li class="chapter" data-level="18.2" data-path="difference-in-differences.html"><a href="difference-in-differences.html#model-1"><i class="fa fa-check"></i><b>18.2</b> Model 1</a>
<ul>
<li class="chapter" data-level="18.2.1" data-path="difference-in-differences.html"><a href="difference-in-differences.html#equivalent-model-1"><i class="fa fa-check"></i><b>18.2.1</b> Equivalent model 1</a></li>
</ul></li>
<li class="chapter" data-level="18.3" data-path="difference-in-differences.html"><a href="difference-in-differences.html#model-2"><i class="fa fa-check"></i><b>18.3</b> Model 2</a></li>
<li class="chapter" data-level="18.4" data-path="difference-in-differences.html"><a href="difference-in-differences.html#comparison-of-models"><i class="fa fa-check"></i><b>18.4</b> Comparison of models</a></li>
<li class="chapter" data-level="18.5" data-path="difference-in-differences.html"><a href="difference-in-differences.html#additional-questions"><i class="fa fa-check"></i><b>18.5</b> Additional questions</a>
<ul>
<li class="chapter" data-level="18.5.1" data-path="difference-in-differences.html"><a href="difference-in-differences.html#question-1"><i class="fa fa-check"></i><b>18.5.1</b> Question 1</a></li>
<li class="chapter" data-level="18.5.2" data-path="difference-in-differences.html"><a href="difference-in-differences.html#question-2"><i class="fa fa-check"></i><b>18.5.2</b> Question 2</a></li>
<li class="chapter" data-level="18.5.3" data-path="difference-in-differences.html"><a href="difference-in-differences.html#question-3"><i class="fa fa-check"></i><b>18.5.3</b> Question 3</a></li>
<li class="chapter" data-level="18.5.4" data-path="difference-in-differences.html"><a href="difference-in-differences.html#question-4"><i class="fa fa-check"></i><b>18.5.4</b> Question 4</a></li>
</ul></li>
<li class="chapter" data-level="18.6" data-path="difference-in-differences.html"><a href="difference-in-differences.html#polynomials"><i class="fa fa-check"></i><b>18.6</b> Polynomials</a></li>
</ul></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">R Programming Guidebook Project</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="joining-data-in-sql" class="section level1" number="11">
<h1><span class="header-section-number">11</span> Joining Data in SQL</h1>
<p><a href="https://learn.datacamp.com/courses/joining-data-in-postgresql" class="uri">https://learn.datacamp.com/courses/joining-data-in-postgresql</a></p>
<div id="introduction-to-joins" class="section level2" number="11.1">
<h2><span class="header-section-number">11.1</span> Introduction to joins</h2>
<p><strong>Inner join</strong></p>
<div class="sourceCode" id="cb572"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb572-1"><a href="joining-data-in-sql.html#cb572-1" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb572-2"><a href="joining-data-in-sql.html#cb572-2" aria-hidden="true" tabindex="-1"></a>FROM left_table</span>
<span id="cb572-3"><a href="joining-data-in-sql.html#cb572-3" aria-hidden="true" tabindex="-1"></a>INNER JOIN right_table</span>
<span id="cb572-4"><a href="joining-data-in-sql.html#cb572-4" aria-hidden="true" tabindex="-1"></a>ON left_table.id <span class="ot">=</span> right_table.id;</span></code></pre></div>
<p>Instead of writing the full table name, you can use table aliasing as a shortcut. For tables you also use <code>AS</code> to add the alias immediately after the table name with a space.</p>
<div class="sourceCode" id="cb573"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb573-1"><a href="joining-data-in-sql.html#cb573-1" aria-hidden="true" tabindex="-1"></a>SELECT c1.name AS city, c2.name AS country</span>
<span id="cb573-2"><a href="joining-data-in-sql.html#cb573-2" aria-hidden="true" tabindex="-1"></a>FROM cities AS c1</span>
<span id="cb573-3"><a href="joining-data-in-sql.html#cb573-3" aria-hidden="true" tabindex="-1"></a>INNER JOIN countries AS c2</span>
<span id="cb573-4"><a href="joining-data-in-sql.html#cb573-4" aria-hidden="true" tabindex="-1"></a>ON c1.country_code <span class="ot">=</span> c2.code;</span></code></pre></div>
<p>Notice that to select a field in your query that appears in multiple tables, you’ll need to identify which table/table alias you’re referring to by using a <code>.</code> in your <code>SELECT</code> statement.</p>
<p>The ability to combine multiple joins in a single query is a powerful feature of SQL:</p>
<div class="sourceCode" id="cb574"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb574-1"><a href="joining-data-in-sql.html#cb574-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb574-2"><a href="joining-data-in-sql.html#cb574-2" aria-hidden="true" tabindex="-1"></a>SELECT c.code, name, region, e.year, fertility_rate, unemployment_rate</span>
<span id="cb574-3"><a href="joining-data-in-sql.html#cb574-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From countries (alias as c)</span></span>
<span id="cb574-4"><a href="joining-data-in-sql.html#cb574-4" aria-hidden="true" tabindex="-1"></a> FROM countries AS c</span>
<span id="cb574-5"><a href="joining-data-in-sql.html#cb574-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Join to populations (as p)</span></span>
<span id="cb574-6"><a href="joining-data-in-sql.html#cb574-6" aria-hidden="true" tabindex="-1"></a> INNER JOIN populations AS p</span>
<span id="cb574-7"><a href="joining-data-in-sql.html#cb574-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Match on country code</span></span>
<span id="cb574-8"><a href="joining-data-in-sql.html#cb574-8" aria-hidden="true" tabindex="-1"></a> ON c.code <span class="ot">=</span> p.country_code</span>
<span id="cb574-9"><a href="joining-data-in-sql.html#cb574-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Join to economies (as e)</span></span>
<span id="cb574-10"><a href="joining-data-in-sql.html#cb574-10" aria-hidden="true" tabindex="-1"></a> INNER JOIN economies AS e</span>
<span id="cb574-11"><a href="joining-data-in-sql.html#cb574-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Match on country code</span></span>
<span id="cb574-12"><a href="joining-data-in-sql.html#cb574-12" aria-hidden="true" tabindex="-1"></a> ON c.code <span class="ot">=</span> e.code;</span></code></pre></div>
<p><strong>Inner join with USING</strong></p>
<p>When joining tables with a common field name, e.g.</p>
<div class="sourceCode" id="cb575"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb575-1"><a href="joining-data-in-sql.html#cb575-1" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb575-2"><a href="joining-data-in-sql.html#cb575-2" aria-hidden="true" tabindex="-1"></a>FROM countries</span>
<span id="cb575-3"><a href="joining-data-in-sql.html#cb575-3" aria-hidden="true" tabindex="-1"></a> INNER JOIN economies</span>
<span id="cb575-4"><a href="joining-data-in-sql.html#cb575-4" aria-hidden="true" tabindex="-1"></a> ON countries.code <span class="ot">=</span> economies.code</span></code></pre></div>
<p>You can use <code>USING</code> as a shortcut:</p>
<div class="sourceCode" id="cb576"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb576-1"><a href="joining-data-in-sql.html#cb576-1" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb576-2"><a href="joining-data-in-sql.html#cb576-2" aria-hidden="true" tabindex="-1"></a>FROM countries</span>
<span id="cb576-3"><a href="joining-data-in-sql.html#cb576-3" aria-hidden="true" tabindex="-1"></a> INNER JOIN economies</span>
<span id="cb576-4"><a href="joining-data-in-sql.html#cb576-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">USING</span>(code)</span></code></pre></div>
<p><strong>CASE WHEN and THEN</strong></p>
<p>Often it’s useful to look at a numerical field not as raw data, but instead as being in different categories or groups.</p>
<p>You can use <code>CASE</code> with <code>WHEN</code>, <code>THEN</code>, <code>ELSE</code>, and <code>END</code> to define a new grouping field.</p>
<div class="sourceCode" id="cb577"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb577-1"><a href="joining-data-in-sql.html#cb577-1" aria-hidden="true" tabindex="-1"></a>SELECT name, continent, code, surface_area,</span>
<span id="cb577-2"><a href="joining-data-in-sql.html#cb577-2" aria-hidden="true" tabindex="-1"></a><span class="co"># First case</span></span>
<span id="cb577-3"><a href="joining-data-in-sql.html#cb577-3" aria-hidden="true" tabindex="-1"></a> CASE WHEN surface_area <span class="sc">></span> <span class="dv">2000000</span> THEN <span class="st">'large'</span></span>
<span id="cb577-4"><a href="joining-data-in-sql.html#cb577-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Second case</span></span>
<span id="cb577-5"><a href="joining-data-in-sql.html#cb577-5" aria-hidden="true" tabindex="-1"></a> WHEN surface_area <span class="sc">></span> <span class="dv">350000</span> THEN <span class="st">'medium'</span></span>
<span id="cb577-6"><a href="joining-data-in-sql.html#cb577-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Else clause + end</span></span>
<span id="cb577-7"><a href="joining-data-in-sql.html#cb577-7" aria-hidden="true" tabindex="-1"></a> ELSE <span class="st">'small'</span> END</span>
<span id="cb577-8"><a href="joining-data-in-sql.html#cb577-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Alias name</span></span>
<span id="cb577-9"><a href="joining-data-in-sql.html#cb577-9" aria-hidden="true" tabindex="-1"></a> AS geosize_group</span>
<span id="cb577-10"><a href="joining-data-in-sql.html#cb577-10" aria-hidden="true" tabindex="-1"></a><span class="co"># From table</span></span>
<span id="cb577-11"><a href="joining-data-in-sql.html#cb577-11" aria-hidden="true" tabindex="-1"></a>FROM countries;</span></code></pre></div>
</div>
<div id="outer-joins-and-cross-joins" class="section level2" number="11.2">
<h2><span class="header-section-number">11.2</span> Outer joins and cross joins</h2>
<p><strong>Left join</strong></p>
<div class="sourceCode" id="cb578"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb578-1"><a href="joining-data-in-sql.html#cb578-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select name, region, and gdp_percapita</span></span>
<span id="cb578-2"><a href="joining-data-in-sql.html#cb578-2" aria-hidden="true" tabindex="-1"></a>SELECT name, region, gdp_percapita</span>
<span id="cb578-3"><a href="joining-data-in-sql.html#cb578-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From countries (alias as c)</span></span>
<span id="cb578-4"><a href="joining-data-in-sql.html#cb578-4" aria-hidden="true" tabindex="-1"></a>FROM countries AS c</span>
<span id="cb578-5"><a href="joining-data-in-sql.html#cb578-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Left join with economies (alias as e)</span></span>
<span id="cb578-6"><a href="joining-data-in-sql.html#cb578-6" aria-hidden="true" tabindex="-1"></a> LEFT JOIN economies AS e</span>
<span id="cb578-7"><a href="joining-data-in-sql.html#cb578-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Match on code fields</span></span>
<span id="cb578-8"><a href="joining-data-in-sql.html#cb578-8" aria-hidden="true" tabindex="-1"></a> ON c.code <span class="ot">=</span> e.code</span>
<span id="cb578-9"><a href="joining-data-in-sql.html#cb578-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Focus on 2010</span></span>
<span id="cb578-10"><a href="joining-data-in-sql.html#cb578-10" aria-hidden="true" tabindex="-1"></a>WHERE year <span class="ot">=</span> <span class="dv">2010</span>;</span></code></pre></div>
<p><strong>Right join</strong></p>
<p>Right joins aren’t as common as left joins. One reason why is that you can always write a right join as a left join.</p>
<div class="sourceCode" id="cb579"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb579-1"><a href="joining-data-in-sql.html#cb579-1" aria-hidden="true" tabindex="-1"></a>SELECT cities.name AS city, urbanarea_pop, countries.name AS country,</span>
<span id="cb579-2"><a href="joining-data-in-sql.html#cb579-2" aria-hidden="true" tabindex="-1"></a> indep_year, languages.name AS language, percent</span>
<span id="cb579-3"><a href="joining-data-in-sql.html#cb579-3" aria-hidden="true" tabindex="-1"></a>FROM languages</span>
<span id="cb579-4"><a href="joining-data-in-sql.html#cb579-4" aria-hidden="true" tabindex="-1"></a> RIGHT JOIN countries</span>
<span id="cb579-5"><a href="joining-data-in-sql.html#cb579-5" aria-hidden="true" tabindex="-1"></a> ON languages.code <span class="ot">=</span> countries.code</span>
<span id="cb579-6"><a href="joining-data-in-sql.html#cb579-6" aria-hidden="true" tabindex="-1"></a> RIGHT JOIN cities</span>
<span id="cb579-7"><a href="joining-data-in-sql.html#cb579-7" aria-hidden="true" tabindex="-1"></a> ON countries.code <span class="ot">=</span> cities.country_code</span>
<span id="cb579-8"><a href="joining-data-in-sql.html#cb579-8" aria-hidden="true" tabindex="-1"></a>ORDER BY city, language;</span></code></pre></div>
<p><strong>Full join</strong></p>
<div class="sourceCode" id="cb580"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb580-1"><a href="joining-data-in-sql.html#cb580-1" aria-hidden="true" tabindex="-1"></a>SELECT name AS country, code, region, basic_unit</span>
<span id="cb580-2"><a href="joining-data-in-sql.html#cb580-2" aria-hidden="true" tabindex="-1"></a><span class="co"># From countries</span></span>
<span id="cb580-3"><a href="joining-data-in-sql.html#cb580-3" aria-hidden="true" tabindex="-1"></a>FROM countries</span>
<span id="cb580-4"><a href="joining-data-in-sql.html#cb580-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Join to currencies</span></span>
<span id="cb580-5"><a href="joining-data-in-sql.html#cb580-5" aria-hidden="true" tabindex="-1"></a> FULL JOIN currencies</span>
<span id="cb580-6"><a href="joining-data-in-sql.html#cb580-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Match on code</span></span>
<span id="cb580-7"><a href="joining-data-in-sql.html#cb580-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">USING</span> (code)</span>
<span id="cb580-8"><a href="joining-data-in-sql.html#cb580-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Where region is North America or null</span></span>
<span id="cb580-9"><a href="joining-data-in-sql.html#cb580-9" aria-hidden="true" tabindex="-1"></a>WHERE region <span class="ot">=</span> <span class="st">'North America'</span> OR region IS <span class="cn">NULL</span></span>
<span id="cb580-10"><a href="joining-data-in-sql.html#cb580-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by region</span></span>
<span id="cb580-11"><a href="joining-data-in-sql.html#cb580-11" aria-hidden="true" tabindex="-1"></a>ORDER BY region;</span></code></pre></div>
</div>
<div id="set-theory-clauses" class="section level2" number="11.3">
<h2><span class="header-section-number">11.3</span> Set theory clauses</h2>
<p><strong>UNION</strong></p>
<p><code>UNION</code> includes every record in both tables but doesn’t double count the matched/overlapped ones.</p>
<div class="sourceCode" id="cb581"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb581-1"><a href="joining-data-in-sql.html#cb581-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields from 2010 table</span></span>
<span id="cb581-2"><a href="joining-data-in-sql.html#cb581-2" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb581-3"><a href="joining-data-in-sql.html#cb581-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From 2010 table</span></span>
<span id="cb581-4"><a href="joining-data-in-sql.html#cb581-4" aria-hidden="true" tabindex="-1"></a> FROM economies2010</span>
<span id="cb581-5"><a href="joining-data-in-sql.html#cb581-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Set theory clause</span></span>
<span id="cb581-6"><a href="joining-data-in-sql.html#cb581-6" aria-hidden="true" tabindex="-1"></a> UNION</span>
<span id="cb581-7"><a href="joining-data-in-sql.html#cb581-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields from 2015 table</span></span>
<span id="cb581-8"><a href="joining-data-in-sql.html#cb581-8" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb581-9"><a href="joining-data-in-sql.html#cb581-9" aria-hidden="true" tabindex="-1"></a><span class="co"># From 2015 table</span></span>
<span id="cb581-10"><a href="joining-data-in-sql.html#cb581-10" aria-hidden="true" tabindex="-1"></a> FROM economies2015</span>
<span id="cb581-11"><a href="joining-data-in-sql.html#cb581-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by code and year</span></span>
<span id="cb581-12"><a href="joining-data-in-sql.html#cb581-12" aria-hidden="true" tabindex="-1"></a>ORDER BY code, year;</span></code></pre></div>
<p><strong>UNION ALL</strong></p>
<p><code>UNION ALL</code> includes every record in both tables and does replicate the matched/overlapped ones.</p>
<div class="sourceCode" id="cb582"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb582-1"><a href="joining-data-in-sql.html#cb582-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb582-2"><a href="joining-data-in-sql.html#cb582-2" aria-hidden="true" tabindex="-1"></a>SELECT code, year</span>
<span id="cb582-3"><a href="joining-data-in-sql.html#cb582-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From economies</span></span>
<span id="cb582-4"><a href="joining-data-in-sql.html#cb582-4" aria-hidden="true" tabindex="-1"></a> FROM economies</span>
<span id="cb582-5"><a href="joining-data-in-sql.html#cb582-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Set theory clause</span></span>
<span id="cb582-6"><a href="joining-data-in-sql.html#cb582-6" aria-hidden="true" tabindex="-1"></a> UNION ALL</span>
<span id="cb582-7"><a href="joining-data-in-sql.html#cb582-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb582-8"><a href="joining-data-in-sql.html#cb582-8" aria-hidden="true" tabindex="-1"></a>SELECT country_code, year</span>
<span id="cb582-9"><a href="joining-data-in-sql.html#cb582-9" aria-hidden="true" tabindex="-1"></a><span class="co"># From populations</span></span>
<span id="cb582-10"><a href="joining-data-in-sql.html#cb582-10" aria-hidden="true" tabindex="-1"></a> FROM populations</span>
<span id="cb582-11"><a href="joining-data-in-sql.html#cb582-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by code, year</span></span>
<span id="cb582-12"><a href="joining-data-in-sql.html#cb582-12" aria-hidden="true" tabindex="-1"></a>ORDER BY code, year;</span></code></pre></div>
<p><strong>INTERSECT</strong></p>
<p><code>INTERSECT</code> results in only those matched/overlapped.</p>
<div class="sourceCode" id="cb583"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb583-1"><a href="joining-data-in-sql.html#cb583-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb583-2"><a href="joining-data-in-sql.html#cb583-2" aria-hidden="true" tabindex="-1"></a>SELECT code, year</span>
<span id="cb583-3"><a href="joining-data-in-sql.html#cb583-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From economies</span></span>
<span id="cb583-4"><a href="joining-data-in-sql.html#cb583-4" aria-hidden="true" tabindex="-1"></a> FROM economies</span>
<span id="cb583-5"><a href="joining-data-in-sql.html#cb583-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Set theory clause</span></span>
<span id="cb583-6"><a href="joining-data-in-sql.html#cb583-6" aria-hidden="true" tabindex="-1"></a> INTERSECT</span>
<span id="cb583-7"><a href="joining-data-in-sql.html#cb583-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb583-8"><a href="joining-data-in-sql.html#cb583-8" aria-hidden="true" tabindex="-1"></a>SELECT country_code, year</span>
<span id="cb583-9"><a href="joining-data-in-sql.html#cb583-9" aria-hidden="true" tabindex="-1"></a><span class="co"># From populations</span></span>
<span id="cb583-10"><a href="joining-data-in-sql.html#cb583-10" aria-hidden="true" tabindex="-1"></a> FROM populations</span>
<span id="cb583-11"><a href="joining-data-in-sql.html#cb583-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by code and year</span></span>
<span id="cb583-12"><a href="joining-data-in-sql.html#cb583-12" aria-hidden="true" tabindex="-1"></a>ORDER BY code, year;</span></code></pre></div>
<p><strong>EXCEPT</strong></p>
<p><code>EXCEPT</code> results in only those doesn’t matched/overlapped.</p>
<div class="sourceCode" id="cb584"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb584-1"><a href="joining-data-in-sql.html#cb584-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select field</span></span>
<span id="cb584-2"><a href="joining-data-in-sql.html#cb584-2" aria-hidden="true" tabindex="-1"></a>SELECT name</span>
<span id="cb584-3"><a href="joining-data-in-sql.html#cb584-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From cities</span></span>
<span id="cb584-4"><a href="joining-data-in-sql.html#cb584-4" aria-hidden="true" tabindex="-1"></a> FROM cities</span>
<span id="cb584-5"><a href="joining-data-in-sql.html#cb584-5" aria-hidden="true" tabindex="-1"></a><span class="co">#Set theory clause</span></span>
<span id="cb584-6"><a href="joining-data-in-sql.html#cb584-6" aria-hidden="true" tabindex="-1"></a> EXCEPT</span>
<span id="cb584-7"><a href="joining-data-in-sql.html#cb584-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Select field</span></span>
<span id="cb584-8"><a href="joining-data-in-sql.html#cb584-8" aria-hidden="true" tabindex="-1"></a>SELECT capital</span>
<span id="cb584-9"><a href="joining-data-in-sql.html#cb584-9" aria-hidden="true" tabindex="-1"></a><span class="co"># From countries</span></span>
<span id="cb584-10"><a href="joining-data-in-sql.html#cb584-10" aria-hidden="true" tabindex="-1"></a> FROM countries</span>
<span id="cb584-11"><a href="joining-data-in-sql.html#cb584-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by result</span></span>
<span id="cb584-12"><a href="joining-data-in-sql.html#cb584-12" aria-hidden="true" tabindex="-1"></a>ORDER BY name;</span></code></pre></div>
<p><strong>Diagnosing problems using anti-join</strong></p>
<p>Another powerful join in SQL is the anti-join. It is particularly useful in identifying which records are causing an incorrect number of records to appear in join queries.</p>
<div class="sourceCode" id="cb585"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb585-1"><a href="joining-data-in-sql.html#cb585-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 3. Select fields</span></span>
<span id="cb585-2"><a href="joining-data-in-sql.html#cb585-2" aria-hidden="true" tabindex="-1"></a>SELECT code, name</span>
<span id="cb585-3"><a href="joining-data-in-sql.html#cb585-3" aria-hidden="true" tabindex="-1"></a><span class="co"># 4. From Countries</span></span>
<span id="cb585-4"><a href="joining-data-in-sql.html#cb585-4" aria-hidden="true" tabindex="-1"></a> FROM countries</span>
<span id="cb585-5"><a href="joining-data-in-sql.html#cb585-5" aria-hidden="true" tabindex="-1"></a><span class="co"># 5. Where continent is Oceania</span></span>
<span id="cb585-6"><a href="joining-data-in-sql.html#cb585-6" aria-hidden="true" tabindex="-1"></a> WHERE continent <span class="ot">=</span> <span class="st">'Oceania'</span></span>
<span id="cb585-7"><a href="joining-data-in-sql.html#cb585-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. And code not in</span></span>
<span id="cb585-8"><a href="joining-data-in-sql.html#cb585-8" aria-hidden="true" tabindex="-1"></a> AND code NOT IN</span>
<span id="cb585-9"><a href="joining-data-in-sql.html#cb585-9" aria-hidden="true" tabindex="-1"></a><span class="co"># 2. Subquery</span></span>
<span id="cb585-10"><a href="joining-data-in-sql.html#cb585-10" aria-hidden="true" tabindex="-1"></a> (SELECT code</span>
<span id="cb585-11"><a href="joining-data-in-sql.html#cb585-11" aria-hidden="true" tabindex="-1"></a> FROM currencies);</span></code></pre></div>
</div>
<div id="subqueries" class="section level2" number="11.4">
<h2><span class="header-section-number">11.4</span> Subqueries</h2>
<p><strong>Subquery inside WHERE</strong></p>
<div class="sourceCode" id="cb586"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb586-1"><a href="joining-data-in-sql.html#cb586-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb586-2"><a href="joining-data-in-sql.html#cb586-2" aria-hidden="true" tabindex="-1"></a>SELECT <span class="sc">*</span></span>
<span id="cb586-3"><a href="joining-data-in-sql.html#cb586-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From populations</span></span>
<span id="cb586-4"><a href="joining-data-in-sql.html#cb586-4" aria-hidden="true" tabindex="-1"></a> FROM populations</span>
<span id="cb586-5"><a href="joining-data-in-sql.html#cb586-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Where life_expectancy is greater than</span></span>
<span id="cb586-6"><a href="joining-data-in-sql.html#cb586-6" aria-hidden="true" tabindex="-1"></a>WHERE life_expectancy <span class="sc">></span></span>
<span id="cb586-7"><a href="joining-data-in-sql.html#cb586-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 1.15 * subquery</span></span>
<span id="cb586-8"><a href="joining-data-in-sql.html#cb586-8" aria-hidden="true" tabindex="-1"></a> <span class="fl">1.15</span> <span class="sc">*</span> (SELECT <span class="fu">AVG</span>(life_expectancy)</span>
<span id="cb586-9"><a href="joining-data-in-sql.html#cb586-9" aria-hidden="true" tabindex="-1"></a> FROM populations</span>
<span id="cb586-10"><a href="joining-data-in-sql.html#cb586-10" aria-hidden="true" tabindex="-1"></a> WHERE <span class="at">year =</span> <span class="dv">2015</span>) AND</span>
<span id="cb586-11"><a href="joining-data-in-sql.html#cb586-11" aria-hidden="true" tabindex="-1"></a> year <span class="ot">=</span> <span class="dv">2015</span>;</span></code></pre></div>
<p><strong>Subquery inside SELECT</strong></p>
<p>The code given in <code>query.sql</code> selects the top nine countries in terms of number of <code>cities</code> appearing in the cities table. Recall that this corresponds to the most populous cities in the world.</p>
<div class="sourceCode" id="cb587"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb587-1"><a href="joining-data-in-sql.html#cb587-1" aria-hidden="true" tabindex="-1"></a>SELECT countries.name AS country, <span class="fu">COUNT</span>(<span class="sc">*</span>) AS cities_num</span>
<span id="cb587-2"><a href="joining-data-in-sql.html#cb587-2" aria-hidden="true" tabindex="-1"></a>FROM cities</span>
<span id="cb587-3"><a href="joining-data-in-sql.html#cb587-3" aria-hidden="true" tabindex="-1"></a>INNER JOIN countries</span>
<span id="cb587-4"><a href="joining-data-in-sql.html#cb587-4" aria-hidden="true" tabindex="-1"></a>ON countries.code <span class="ot">=</span> cities.country_code</span>
<span id="cb587-5"><a href="joining-data-in-sql.html#cb587-5" aria-hidden="true" tabindex="-1"></a>GROUP BY country</span>
<span id="cb587-6"><a href="joining-data-in-sql.html#cb587-6" aria-hidden="true" tabindex="-1"></a>ORDER BY cities_num DESC, country</span>
<span id="cb587-7"><a href="joining-data-in-sql.html#cb587-7" aria-hidden="true" tabindex="-1"></a>LIMIT <span class="dv">9</span>;</span></code></pre></div>
<p>convert the code to get the same result as the code shown:</p>
<div class="sourceCode" id="cb588"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb588-1"><a href="joining-data-in-sql.html#cb588-1" aria-hidden="true" tabindex="-1"></a>SELECT countries.name AS country,</span>
<span id="cb588-2"><a href="joining-data-in-sql.html#cb588-2" aria-hidden="true" tabindex="-1"></a>(SELECT <span class="fu">COUNT</span>(<span class="sc">*</span>)</span>
<span id="cb588-3"><a href="joining-data-in-sql.html#cb588-3" aria-hidden="true" tabindex="-1"></a>FROM cities</span>
<span id="cb588-4"><a href="joining-data-in-sql.html#cb588-4" aria-hidden="true" tabindex="-1"></a>WHERE <span class="at">countries.code =</span> cities.country_code) AS cities_num</span>
<span id="cb588-5"><a href="joining-data-in-sql.html#cb588-5" aria-hidden="true" tabindex="-1"></a>FROM countries</span>
<span id="cb588-6"><a href="joining-data-in-sql.html#cb588-6" aria-hidden="true" tabindex="-1"></a>ORDER BY cities_num DESC, country</span>
<span id="cb588-7"><a href="joining-data-in-sql.html#cb588-7" aria-hidden="true" tabindex="-1"></a>LIMIT <span class="dv">9</span>;</span></code></pre></div>
<p><strong>Subquery inside FROM</strong></p>
<p>Begin by determining for each country code how many <code>languages</code> are listed in the languages table using <code>SELECT</code>, <code>FROM</code>, and <code>GROUP BY</code>.</p>
<p>Alias the aggregated field as <code>lang_num</code>.</p>
<div class="sourceCode" id="cb589"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb589-1"><a href="joining-data-in-sql.html#cb589-1" aria-hidden="true" tabindex="-1"></a><span class="sc">--</span> Select <span class="fu">fields</span> (with aliases)</span>
<span id="cb589-2"><a href="joining-data-in-sql.html#cb589-2" aria-hidden="true" tabindex="-1"></a>SELECT code, <span class="fu">COUNT</span>(name) AS lang_num</span>
<span id="cb589-3"><a href="joining-data-in-sql.html#cb589-3" aria-hidden="true" tabindex="-1"></a><span class="sc">--</span> From languages</span>
<span id="cb589-4"><a href="joining-data-in-sql.html#cb589-4" aria-hidden="true" tabindex="-1"></a>FROM languages</span>
<span id="cb589-5"><a href="joining-data-in-sql.html#cb589-5" aria-hidden="true" tabindex="-1"></a><span class="sc">--</span> Group by code</span>
<span id="cb589-6"><a href="joining-data-in-sql.html#cb589-6" aria-hidden="true" tabindex="-1"></a>GROUP BY code;</span></code></pre></div>
<p>Include the previous query (aliased as <code>subquery</code>) as a subquery in the <code>FROM</code> clause of a new query.</p>
<p>Select the local name of the country from <code>countries.</code></p>
<p>Also, select <code>lang_num</code> from subquery.</p>
<p>Make sure to use <code>WHERE</code> appropriately to match <code>code</code> in <code>countries</code> and in <code>subquery</code>.</p>
<p>Sort by <code>lang_num</code> in descending order.</p>
<div class="sourceCode" id="cb590"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb590-1"><a href="joining-data-in-sql.html#cb590-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select fields</span></span>
<span id="cb590-2"><a href="joining-data-in-sql.html#cb590-2" aria-hidden="true" tabindex="-1"></a>SELECT local_name, subquery.lang_num</span>
<span id="cb590-3"><a href="joining-data-in-sql.html#cb590-3" aria-hidden="true" tabindex="-1"></a><span class="co"># From countries</span></span>
<span id="cb590-4"><a href="joining-data-in-sql.html#cb590-4" aria-hidden="true" tabindex="-1"></a>FROM countries,</span>
<span id="cb590-5"><a href="joining-data-in-sql.html#cb590-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Subquery (alias as subquery)</span></span>
<span id="cb590-6"><a href="joining-data-in-sql.html#cb590-6" aria-hidden="true" tabindex="-1"></a>(SELECT code, <span class="fu">COUNT</span>(name) AS lang_num</span>
<span id="cb590-7"><a href="joining-data-in-sql.html#cb590-7" aria-hidden="true" tabindex="-1"></a>FROM languages</span>
<span id="cb590-8"><a href="joining-data-in-sql.html#cb590-8" aria-hidden="true" tabindex="-1"></a>GROUP BY code) AS subquery</span>
<span id="cb590-9"><a href="joining-data-in-sql.html#cb590-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Where codes match</span></span>
<span id="cb590-10"><a href="joining-data-in-sql.html#cb590-10" aria-hidden="true" tabindex="-1"></a>WHERE countries.code <span class="ot">=</span> subquery.code</span>
<span id="cb590-11"><a href="joining-data-in-sql.html#cb590-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Order by descending number of languages</span></span>
<span id="cb590-12"><a href="joining-data-in-sql.html#cb590-12" aria-hidden="true" tabindex="-1"></a>ORDER BY lang_num DESC;</span></code></pre></div>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="introduction-to-sql.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="web-scraping-in-r.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/alecng27/R_Programming_Guidebook/edit/master/11-Joining_Data_in_SQL.Rmd",
"text": "Edit"
},
"history": {
"link": "https://github.com/alecng27/R_Programming_Guidebook/commits/master/11-Joining_Data_in_SQL.Rmd",
"text": null
},
"view": {
"link": "https://github.com/alecng27/R_Programming_Guidebook/blob/master/11-Joining_Data_in_SQL.Rmd",
"text": null
},
"download": null,
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "section"
}
});
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
var src = "true";
if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
if (location.protocol !== "file:")
if (/^https?:/.test(src))
src = src.replace(/^https?:/, '');
script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>