-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
518 lines (438 loc) · 195 KB
/
index.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
<!DOCTYPE html>
<!-- Created by pdf2htmlEX (https://github.com/coolwanglu/pdf2htmlex) -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<meta name="generator" content="pdf2htmlEX"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content="slides for Advanced SQL for the course of Web- and Database Technology at the Delft University of Technology" />
<meta name="author" content="Alessandro Bozzon, Vasileios Triglianos" />
<title>Advanced SQL</title>
<link rel="stylesheet" href="css/base.min.css"/>
<link rel="stylesheet" href="css/pdf-styles.css"/>
<link rel="stylesheet" href="css/ASQBasicImpress.css">
<link rel="stylesheet" href="css/style.css"/>
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<!-- Use shadow dom -->
<script>
window.Polymer = window.Polymer || {};
window.Polymer.dom = 'shadow';
</script>
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="bower_components/asq-elements/asq-elements.html">
<link href="bower_components/usi-web-atelier-slides-common/css/sunburst.css" rel="stylesheet">
<link rel="import" href="shared-styles.html">
<style is="custom-style" include="shared-styles"></style>
</head>
<body class="impress-not-supported">
<div class="fallback-message">
<p>
Your browser <b>doesn't support the features required</b> by impress.js, so you are presented with a simplified version of this presentation.
</p>
<p>
For the best experience please use the latest <b>Chrome</b>, <b>Safari</b> or <b>Firefox</b> browser.
</p>
</div>
<!--<asq-settings max-num-submissions="1" slideflow="ctrl"></asq-settings>-->
<div id="impress">
<div id="pf1" class="step pf w0 h0" data-x="-500" data-y="0" data-scale="0.4" data-page-no="1">
<div style="position: absolute; z-index: 2;">
<div class="small">slack-channel: <a style="color: rgb(232,164,51); background: none;" href="ti1506-students.slack.nl">ti1506-students.slack.nl</a> </div>
</div>
<div class="small" style="position: absolute;
z-index: 2;
top: 90px;
left: 87px;
width: 850px;
height: 100px;
background: rgba(0,0,0, 0.7);">
<asq-welcome class="small"></asq-welcome>
</div>
<div class="pc pc1 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1.png"/><div class="t m0 x1 h1 y1 ff1 fs0 fc0 sc0 ls0 ws0">Alessandro Bozzon</div><div class="t m0 x2 h2 y2 ff2 fs0 fc0 sc0 ls0 ws0">TI1506: W<span class="_ _0"></span>eb and Database T<span class="_ _1"></span>echnology </div><div class="t m0 x3 h1 y3 ff1 fs0 fc0 sc0 ls0 ws0">[email protected]</div><div class="t m0 x4 h3 y4 ff2 fs1 fc1 sc0 ls0 ws0">Advanced SQL T<span class="_ _2"></span>opics</div><a class="l" href="mailto:[email protected]"><div class="d m1" style="border-style:none;position:absolute;left:352.375000px;bottom:199.875000px;width:319.250000px;height:38.000000px;background-color:rgba(255,255,255,0.000001);"></div></a></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div>
<!-- <asq-welcome style="position: relative; top: -75px; transform: scale(0.8); text-align: center; color: white; text-shadow: 1px 1px rgba(0,0,0,0.5);"></asq-welcome>
<div style="position: relative; top: 340px; text-align: center; color: white; text-shadow: 1px 1px rgba(0,0,0,0.5);">Connect to http://145.100.58.142/asq/live</div>-->
</div>
<div id="announcements" class="step" data-x="0" data-y="0" data-scale="0.4" data-rotate="0"><div style="height: 400px; padding: 20px 20px; background: rgba(255, 255, 255, 0.6); margin-top: 20px;"><div><h2><b>Announcements</b></h2></div><center><h2><font color="#8B008B">ToDuel</font></h2></center><div><center>Video submission deadline: January 15th, 23:59</center></div></div></div>
<div id="pf2" class="step pf w0 h0" data-x="500" data-y="0" data-scale="0.4" data-page-no="2"><div class="pc pc2 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Course o<span class="_ _0"></span>v<span class="_ _3"></span>er<span class="_ _4"></span>vie<span class="_ _5"></span>w [DB]</div><div class="t m0 x6 h5 y6 ff2 fs3 fc2 sc0 ls0 ws0">1.</div><div class="t m0 x7 h5 y7 ff2 fs3 fc2 sc0 ls0 ws0">Intr<span class="_ _0"></span>oduction to Database Systems </div><div class="t m0 x6 h5 y8 ff2 fs3 fc2 sc0 ls0 ws0">2.</div><div class="t m0 x7 h5 y9 ff2 fs3 fc2 sc0 ls0 ws0">The Relational Model </div><div class="t m0 x6 h5 ya ff2 fs3 fc2 sc0 ls0 ws0">3.</div><div class="t m0 x7 h5 yb ff2 fs3 fc2 sc0 ls0 ws0">Intr<span class="_ _0"></span>oduction to SQL </div><div class="t m0 x6 h6 yc ff1 fs3 fc3 sc0 ls1 ws0">4.</div><div class="t m0 x7 h6 yd ff1 fs3 fc3 sc0 ls0 ws0">Advanced SQL<span class="_ _0"></span> T<span class="_ _6"></span>opics</div><div class="t m0 x6 h5 ye ff2 fs3 fc2 sc0 ls0 ws0">5.</div><div class="t m0 x7 h5 yf ff2 fs3 fc2 sc0 ls0 ws0">Intr<span class="_ _0"></span>oduction to NoSQL database systems </div><div class="t m0 x6 h5 y10 ff2 fs3 fc2 sc0 ls0 ws0">6.</div><div class="t m0 x7 h5 y11 ff2 fs3 fc2 sc0 ls0 ws0">Conceptual Data Modelling with ER Diagrams </div><div class="t m0 x6 h5 y12 ff2 fs3 fc2 sc0 ls0 ws0">7.</div><div class="t m0 x7 h5 y13 ff2 fs3 fc2 sc0 ls0 ws0">Database Conceptual Design </div><div class="t m0 x6 h5 y14 ff2 fs3 fc2 sc0 ls0 ws0">8.</div><div class="t m0 x7 h5 y15 ff2 fs3 fc2 sc0 ls0 ws0">Database Logical Design</div><div class="t m0 x8 h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">2</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-1" class="step pf w0 h0" data-x="1000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<h3>Warmup Exercise</h3>
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>How many audio tracks in total were bought by German customers? And what was the total price paid for them? <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.1 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>How many audio tracks in total were bought by German customers? And what was the total price paid for them? <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT COUNT(t.trackId), SUM(l.unitprice)
FROM invoiceLine l, invoice i, customer c, track t,
mediaType m
WHERE l.invoiceId = i.invoiceId
AND i.customerId = c.customerId
AND c.country = 'Germany'
AND l.trackId = t.trackId
AND t.mediaTypeId = m.mediaTypeId
AND m.name LIKE '%audio%'</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf4" class="step pf w0 h0" data-x="1500" data-y="0" data-scale="0.4" data-page-no="4"><div class="pc pc4 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg4.png"/><div class="t m0 x11 he y28 ff3 fs8 fc2 sc0 ls0 ws0">Nested Queries</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf5" class="step pf w0 h0" data-x="2000" data-y="0" data-scale="0.4" data-page-no="5"><div class="pc pc5 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg5.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Subqueries</div><div class="t m0 x5 hf y29 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x12 ha y2a ff2 fs6 fc2 sc0 ls0 ws0">A par<span class="_ _0"></span>enthesised <span class="ff5 ls3">SELECT-FROM-WHERE</span> statement can be used as a </div><div class="t m0 x12 ha y2b ff2 fs6 fc2 sc0 ls0 ws0">value in a number of places, including <span class="ff5 ls3">FROM</span>, <span class="ff5 ls3">WHERE</span>, and <span class="ff5 ls3">HAVING</span> </div><div class="t m0 x12 ha y2c ff2 fs6 fc2 sc0 ls0 ws0">clauses </div><div class="t m0 x13 hf y2d ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x14 h10 y2e ff1 fs6 fc2 sc0 ls4 ws0">subquery<span class="ff2 ls0"> or <span class="ff1">nested query</span></span></div><div class="t m0 x13 hf y2f ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x14 ha y30 ff2 fs6 fc2 sc0 ls0 ws0">Example: in place of a r<span class="_ _0"></span>elation in the <span class="ff5 ls3">FROM</span> clause, we can place </div><div class="t m0 x14 ha y31 ff2 fs6 fc2 sc0 ls0 ws0">another quer<span class="_ _9"></span>y<span class="_ _a"></span>, and then asser<span class="_ _9"></span>t a condition on its r<span class="_ _0"></span>esults </div><div class="t m0 x5 hf y32 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x12 ha y33 ff2 fs6 fc2 sc0 ls0 ws0">A common use of subqueries is to per<span class="_ _9"></span>for<span class="_ _9"></span>m tests for <span class="ff6">set membership</span>, </div><div class="t m0 x12 ha y34 ff6 fs6 fc2 sc0 ls0 ws0">set comparisons<span class="ff2">, and </span>set car<span class="_ _0"></span>dinality<span class="ff2"> </span></div><div class="t m0 x5 hf y35 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x12 ha y36 ff2 fs6 fc2 sc0 ls0 ws0">The use of nested queries may pr<span class="_ _0"></span>oduce less declarative queries, but </div><div class="t m0 x12 ha y37 ff2 fs6 fc2 sc0 ls0 ws0">they often impr<span class="_ _0"></span>ove r<span class="_ _0"></span>eadability </div><div class="t m0 x5 hf y38 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x12 ha y39 ff2 fs6 fc2 sc0 ls0 ws0">Complex queries can become ver<span class="_ _9"></span>y dif<span class="_ _0"></span>ficult to understand </div><div class="t m0 x8 h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">5</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf6" class="step pf w0 h0" data-x="2500" data-y="0" data-scale="0.4" data-page-no="6"><div class="pc pc6 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg6.png"/><div class="t m0 x5 h11 y3a ff3 fsa fc2 sc0 ls0 ws0">The <span class="ff5 ls5">IN</span> Operator</div><div class="t m0 x6 hf y3b ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x15 h10 y3c ff5 fs6 fc2 sc0 ls3 ws0"><tuple> IN <relation><span class="ff2 ls0"> is <span class="ff1">true</span> <span class="ff1">if and only if</span> the tuple is a </span></div><div class="t m0 x15 ha y3d ff2 fs6 fc2 sc0 ls0 ws0">member of the r<span class="_ _0"></span>elations </div><div class="t m0 x16 hf y3e ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x17 ha y3f ff5 fs6 fc2 sc0 ls3 ws0"><tuple> NOT IN <relation><span class="ff2 ls0"> means the opposite </span></div><div class="t m0 x6 hf y40 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x15 ha y41 ff5 fs6 fc2 sc0 ls3 ws0">IN<span class="ff2 ls0"> expr<span class="_ _0"></span>ession can appear in <span class="ff5 ls3">WHERE</span> clauses </span></div><div class="t m0 x16 hf y42 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x17 ha y43 ff2 fs6 fc2 sc0 ls0 ws0">The r<span class="_ _0"></span>elation is often a subquer<span class="_ _9"></span>y </div><div class="t m0 x18 hf y44 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x19 ha y45 ff2 fs6 fc2 sc0 ls0 ws0">e.g. <span class="ff7 ls3">WHERE firstName IN ( SELECT lastName FROM </span></div><div class="t m0 x19 ha y46 ff7 fs6 fc2 sc0 ls3 ws0">EMPLOYEE)<span class="ff2 ls0"> </span></div><div class="t m0 x16 hf y47 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x17 ha y48 ff2 fs6 fc2 sc0 ls0 ws0">It is possible to specify a pr<span class="_ _0"></span>e-defined list of values </div><div class="t m0 x18 hf y49 ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x19 ha y4a ff2 fs6 fc2 sc0 ls0 ws0">e.g. <span class="ff7 ls3">WHERE firstName IN (‘Jan’, ‘Arie’, ‘Henk’)</span> </div><div class="t m0 x6 hf y4b ff2 fs9 fc2 sc0 ls0 ws0">•</div><div class="t m0 x15 ha y4c ff2 fs6 fc2 sc0 ls0 ws0">It allows pr<span class="_ _0"></span>oblem decomposition, typically with a “bottom-up” appr<span class="_ _0"></span>oach</div><div class="t m0 x8 h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">6</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf7" class="step pf w0 h0" data-x="3000" data-y="0" data-scale="0.4" data-page-no="7"><div class="pc pc7 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg7.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /1</div><div class="c xa y4d w3 h9"><div class="t m0 xb ha y4e ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers that </div><div class="t m0 x1a ha y4f ff2 fs6 fc2 sc0 ls0 ws0">supply pr<span class="_ _0"></span>oduct P2 </div></div><div class="t m0 x8 h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">7</div><div class="c x1b y50 w4 h12"><div class="t m0 x1c h2 y51 ff2 fs0 fc2 sc0 ls0 ws0">With Join</div></div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c x1b y54 w6 h12"><div class="t m0 x1f h2 y55 ff2 fs0 fc2 sc0 ls0 ws0">With Nested Queries</div></div><div class="c x20 y56 w7 h15"><div class="t m3 x21 h16 y57 ff8 fsc fc4 sc0 ls0 ws0">Example<span class="_ _b"> </span>/1</div><div class="t m3 x22 h17 y58 ff9 fsd fc2 sc0 ls0 ws0">Find<span class="_ _c"> </span>the<span class="_ _c"> </span>name<span class="_ _c"> </span>of<span class="_ _c"> </span>the<span class="_ _c"> </span>suppliers<span class="_ _c"> </span>that<span class="_ _c"> </span>supply<span class="_ _c"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>duct<span class="_ _c"> </span>P2</div><div class="t m3 x22 h17 y59 ff9 fsd fc2 sc0 ls0 ws0">Tw<span class="_ _5"></span>o<span class="_ _c"> </span>subp<span class="_ _5"></span>roblems</div><div class="t m3 x23 h18 y5a ff9 fse fc2 sc0 ls0 ws0">Co<span class="_ _d"></span>de<span class="_ _e"> </span>of<span class="_ _e"> </span>P2<span class="_ _e"> </span>s up p l i er s</div><div class="t m3 x23 h18 y5b ff9 fse fc2 sc0 ls0 ws0">Name<span class="_ _e"> </span>of<span class="_ _f"> </span>such<span class="_ _e"> </span>suppl ie r s</div><div class="t m3 x22 h19 y5c ffa fsf fc5 sc0 ls0 ws0">SELECT<span class="_ _10"> </span><span class="fc2">NameS</span></div><div class="t m3 x22 h19 y5d ffa fsf fc5 sc0 ls0 ws0">FROM<span class="_ _10"> </span><span class="fc2">Supplier</span></div><div class="t m3 x22 h19 y5e ffa fsf fc5 sc0 ls0 ws0">WHERE<span class="_ _10"> </span><span class="fc2">CodeS<span class="_ _10"> </span></span>IN<span class="_ _10"> </span><span class="fc2">(</span>SELECT<span class="_ _10"> </span><span class="fc2">CodeS</span></div><div class="t m3 x24 h19 y5f ffa fsf fc5 sc0 ls0 ws0">FROM<span class="_ _10"> </span><span class="fc2">Supply</span></div><div class="t m3 x24 h19 y60 ffa fsf fc5 sc0 ls0 ws0">WHERE<span class="_ _10"> </span><span class="fc2">CodeP<span class="_ _10"> </span><span class="fc6">=<span class="_ _10"> </span><span class="fc7">"P2"</span></span>)</span></div><div class="t m3 x23 h18 y61 ff9 fse fc2 sc0 ls0 ws0">Could<span class="_ _e"> </span>b<span class="_ _d"></span>e<span class="_ _e"> </span>done<span class="_ _f"> </span>with<span class="_ _e"> </span>a<span class="_ _f"> </span><span class="ffb">JOIN?</span></div><div class="t m3 x23 h18 y62 ff9 fse fc2 sc0 ls7 ws0">Ye<span class="_ _11"></span>s<span class="_ _11"></span>!<span class="_ _11"></span>!</div><div class="t m3 x23 h19 y63 ffa fsf fc5 sc0 ls0 ws0">SELECT<span class="_ _10"> </span><span class="fc2">NameS</span></div><div class="t m3 x23 h19 y64 ffa fsf fc5 sc0 ls0 ws0">FROM<span class="_ _10"> </span><span class="fc2">Supplier,<span class="_ _10"> </span>Supply</span></div><div class="t m3 x23 h19 y65 ffa fsf fc5 sc0 ls0 ws0">WHERE<span class="_ _10"> </span><span class="fc2">Supplier.CodeS<span class="fc6">=</span>Supply.CodeS<span class="_ _10"> </span></span>AND<span class="_ _10"> </span><span class="fc2">CodeP<span class="_ _10"> </span><span class="fc6">=<span class="_ _10"> </span><span class="fc7">"P2"</span></span></span></div><div class="t m3 x25 h1a y66 ffc fs10 fc1 sc0 ls8 ws0">Advanced<span class="_ _12"> </span>SQL<span class="_ _12"> </span>Queries<span class="_ _13"> </span>36<span class="_ _12"> </span>/<span class="_ _12"> </span>74</div></div><div class="c x26 y67 w8 h1b"><div class="t m0 x27 h2 y68 ff2 fs0 fc1 sc0 ls0 ws0">T<span class="_ _a"></span>wo Subpr<span class="_ _0"></span>oblems </div><div class="t m0 x27 h8 y69 ff2 fs5 fc1 sc0 ls0 ws0">•</div><div class="t m0 xa h2 y6a ff2 fs0 fc1 sc0 ls0 ws0">Code of P2 suppliers </div><div class="t m0 x27 h8 y6b ff2 fs5 fc1 sc0 ls0 ws0">•</div><div class="t m0 xa h2 y6c ff2 fs0 fc1 sc0 ls0 ws0">Name of such suppliers</div></div><div class="c x6 y4c w9 h1c"><div class="t m4 x28 h1d y6d ffd fs11 fc4 sc0 ls0 ws0">Example<span class="_ _14"> </span>/1</div><div class="t m4 x29 h1e y6e ffe fs12 fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _15"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>th e<span class="_ _15"> </span>suppliers<span class="_ _15"> </span>that<span class="_ _f"> </span>supply<span class="_ _15"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>duct<span class="_ _f"> </span>P2</div><div class="t m4 x29 h1e y6f ffe fs12 fc2 sc0 ls0 ws0">Tw<span class="_ _5"></span>o<span class="_ _f"> </span>su bp<span class="_ _0"></span>roblems</div><div class="t m4 x13 h1f y70 ffe fs13 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _16"> </span>of<span class="_ _16"> </span>P2<span class="_ _17"> </span>suppliers</div><div class="t m4 x13 h1f y71 ffe fs13 fc2 sc0 ls0 ws0">Name<span class="_ _17"> </span>of<span class="_ _16"> </span>such<span class="_ _16"> </span>suppliers</div><div class="t m4 x29 h20 y72 fff fs14 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t m4 x29 h20 y73 fff fs14 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t m4 x29 h20 y74 fff fs14 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeS<span class="_ _18"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(</span>SELECT<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t m4 x2a h20 y75 fff fs14 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t m4 x2a h20 y76 fff fs14 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"P2"</span></span>)</span></div><div class="t m4 x13 h1f y77 ffe fs13 fc2 sc0 ls0 ws0">Could<span class="_ _17"> </span>b<span class="_ _d"></span>e<span class="_ _16"> </span>done<span class="_ _17"> </span>with<span class="_ _16"> </span>a<span class="_ _17"> </span><span class="ff10">JOIN?</span></div><div class="t m4 x13 h1f y78 ffe fs13 fc2 sc0 ls9 ws0">Ye<span class="_ _11"></span>s<span class="_ _19"></span>!<span class="_ _19"></span>!</div><div class="t m4 x13 h20 y79 fff fs14 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t m4 x13 h20 y7a fff fs14 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier,<span class="_ _18"> </span>Supply</span></div><div class="t m4 x13 h20 y7b fff fs14 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Supplier.CodeS<span class="fc6">=</span>Supply.CodeS<span class="_ _18"> </span></span>AND<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"P2"</span></span></span></div><div class="t m4 x2b h21 y7c ff11 fs15 fc1 sc0 lsa ws0">Advanced<span class="_ _1a"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _1b"> </span>36<span class="_ _1a"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf8" class="step pf w0 h0" data-x="3500" data-y="0" data-scale="0.4" data-page-no="8"><div class="pc pc8 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg8.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /2</div><div class="c xa y4d w3 h9"><div class="t m0 xb ha y4e ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers that </div><div class="t m0 x2c ha y4f ff2 fs6 fc2 sc0 ls0 ws0">supply at least one r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oduct </div></div><div class="t m0 x8 h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">8</div><div class="c x2d y7d w4 h12"><div class="t m0 x1c h2 y7e ff2 fs0 fc2 sc0 ls0 ws0">With Join</div></div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c x1b y7f w6 h12"><div class="t m0 x1f h2 y55 ff2 fs0 fc2 sc0 ls0 ws0">With Nested Queries</div></div><div class="c x2e y80 w8 h22"><div class="t m0 x27 h2 y81 ff2 fs0 fc1 sc0 ls0 ws0">Thr<span class="_ _0"></span>ee subpr<span class="_ _0"></span>oblems </div><div class="t m0 x27 h8 y82 ff2 fs5 fc1 sc0 ls0 ws0">•</div><div class="t m0 xa h2 y83 ff2 fs0 fc1 sc0 ls0 ws0">Code of r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts, </div><div class="t m0 x27 h8 y84 ff2 fs5 fc1 sc0 ls0 ws0">•</div><div class="t m0 xa h2 y85 ff2 fs0 fc1 sc0 ls0 ws0">Code of suppliers that </div><div class="t m0 xa h2 y86 ff2 fs0 fc1 sc0 ls0 ws0">supply such pr<span class="_ _0"></span>oducts </div><div class="t m0 x27 h8 y6b ff2 fs5 fc1 sc0 ls0 ws0">•</div><div class="t m0 xa h2 y87 ff2 fs0 fc1 sc0 ls0 ws0">Name of such suppliers </div></div><div class="c x2d y88 wa h23"><div class="t m5 x2f h24 y89 ff12 fs16 fc4 sc0 ls0 ws0">Example<span class="_ _b"> </span>/2</div><div class="t m5 x30 h25 y8a ff13 fs17 fc2 sc0 ls0 ws0">Find<span class="_ _16"> </span>th e<span class="_ _e"> </span>name<span class="_ _e"> </span>of<span class="_ _16"> </span>the<span class="_ _e"> </span>suppliers<span class="_ _e"> </span>that<span class="_ _e"> </span>supply<span class="_ _16"> </span>at<span class="_ _e"> </span>least<span class="_ _e"> </span>one<span class="_ _16"> </span>red<span class="_ _e"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>duct</div><div class="t m5 x30 h25 y8b ff13 fs17 fc2 sc0 ls0 ws0">Three<span class="_ _16"> </span>su b p<span class="_ _0"></span>roblems</div><div class="t m5 x31 h26 y8c ff13 fs18 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _17"> </span>of<span class="_ _1c"> </span>red<span class="_ _1c"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts,<span class="_ _17"> </span>Co<span class="_ _9"></span>de<span class="_ _1c"> </span>of<span class="_ _17"> </span>suppliers<span class="_ _1c"> </span>that<span class="_ _17"> </span>supply<span class="_ _1c"> </span>such<span class="_ _1c"> </span>p<span class="_ _0"></span>ro<span class="_ _d"></span>ducts,<span class="_ _1c"> </span>Name<span class="_ _1c"> </span>of</div><div class="t m5 x31 h26 y8d ff13 fs18 fc2 sc0 lsb ws0">such<span class="_ _1c"> </span>suppliers</div><div class="t m5 x30 h27 y8e ff14 fs19 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">NameS</span></div><div class="t m5 x30 h27 y8f ff14 fs19 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supplier</span></div><div class="t m5 x30 h27 y90 ff14 fs19 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">CodeS<span class="_ _1d"> </span></span>IN<span class="_ _1d"> </span><span class="fc2">(</span>SELECT<span class="_ _1d"> </span><span class="fc2">CodeS</span></div><div class="t m5 x32 h27 y91 ff14 fs19 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supply</span></div><div class="t m5 x32 h27 y92 ff14 fs19 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">CodeP<span class="_ _1d"> </span></span>IN<span class="fc2">(<span class="_ _1d"> </span></span>SELECT<span class="_ _1d"> </span><span class="fc2">CodeP</span></div><div class="t m5 x33 h27 y93 ff14 fs19 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Products</span></div><div class="t m5 x33 h27 y94 ff14 fs19 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Color<span class="fc6">=<span class="fc7">"red"</span></span>))</span></div><div class="t m5 x31 h26 y95 ff13 fs18 fc2 sc0 ls0 ws0">Could<span class="_ _1c"> </span>b<span class="_ _d"></span>e<span class="_ _1c"> </span>done<span class="_ _1c"> </span>with<span class="_ _1c"> </span>a<span class="_ _17"> </span><span class="ff15">JOIN?</span></div><div class="t m5 x31 h26 y96 ff13 fs18 fc2 sc0 lsc ws0">Ye<span class="_ _19"></span>s<span class="_ _19"></span>!<span class="_ _19"></span>!</div><div class="t m5 x31 h27 y97 ff14 fs19 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">NameS</span></div><div class="t m5 x31 h27 y98 ff14 fs19 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supplier,<span class="_ _1d"> </span>Supply,<span class="_ _1d"> </span>Product</span></div><div class="t m5 x31 h27 y99 ff14 fs19 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Supplier.CodeS<span class="fc6">=</span>Supply.CodeS<span class="_ _1d"> </span></span>AND<span class="_ _1d"> </span><span class="fc2">Supply.CodeP<span class="_ _1d"> </span><span class="fc6">=<span class="_ _1d"> </span></span>Product.CodeP<span class="_ _1d"> </span></span>AND</div><div class="t m5 x34 h27 y9a ff14 fs19 fc2 sc0 ls0 ws0">Product.CodeP<span class="_ _1d"> </span><span class="fc6">=<span class="_ _1d"> </span><span class="fc7">"P2"</span></span></div><div class="t m5 x35 h28 y9b ff16 fs1a fc1 sc0 lsd ws0">Advanced<span class="_ _12"> </span>SQL<span class="_ _12"> </span>Queries<span class="_ _1e"> </span>37<span class="_ _12"> </span>/<span class="_ _12"> </span>74</div></div><div class="c x36 y9c wa h29"><div class="t m6 x37 h2a y9d ff17 fs1b fc4 sc0 ls0 ws0">Example<span class="_ _14"> </span>/2</div><div class="t m6 x31 h2b y9e ff18 fs1c fc2 sc0 ls0 ws0">Find<span class="_ _17"> </span>the<span class="_ _17"> </span>name<span class="_ _17"> </span>of<span class="_ _17"> </span>the<span class="_ _17"> </span>suppliers<span class="_ _17"> </span>that<span class="_ _17"> </span>suppl y<span class="_ _17"> </span>at<span class="_ _17"> </span>leas t<span class="_ _17"> </span>one<span class="_ _17"> </span>red<span class="_ _17"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>d u ct</div><div class="t m6 x31 h2b y9f ff18 fs1c fc2 sc0 ls0 ws0">Three<span class="_ _17"> </span>subp<span class="_ _0"></span>roblems</div><div class="t m6 x38 h2c ya0 ff18 fs1d fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _1f"> </span>of<span class="_ _1f"> </span>red<span class="_ _1f"> </span>p<span class="_ _5"></span>ro<span class="_ _9"></span>ducts,<span class="_ _1f"> </span>Co<span class="_ _9"></span>d e<span class="_ _1f"> </span>of<span class="_ _1f"> </span>suppliers<span class="_ _1f"> </span>that<span class="_ _1f"> </span>supply<span class="_ _20"> </span>such<span class="_ _20"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>du cts ,<span class="_ _1f"> </span>Name<span class="_ _20"> </span>of</div><div class="t m6 x38 h2c ya1 ff18 fs1d fc2 sc0 lse ws0">such<span class="_ _20"> </span>suppliers</div><div class="t m6 x31 h2d ya2 ff19 fs1e fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">NameS</span></div><div class="t m6 x31 h2d ya3 ff19 fs1e fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supplier</span></div><div class="t m6 x31 h2d ya4 ff19 fs1e fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">CodeS<span class="_ _21"> </span></span>IN<span class="_ _21"> </span><span class="fc2">(</span>SELECT<span class="_ _21"> </span><span class="fc2">CodeS</span></div><div class="t m6 x39 h2d ya5 ff19 fs1e fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supply</span></div><div class="t m6 x39 h2d ya6 ff19 fs1e fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">CodeP<span class="_ _21"> </span></span>IN<span class="fc2">(<span class="_ _21"> </span></span>SELECT<span class="_ _21"> </span><span class="fc2">CodeP</span></div><div class="t m6 x3a h2d ya7 ff19 fs1e fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Products</span></div><div class="t m6 x3a h2d ya8 ff19 fs1e fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Color<span class="fc6">=<span class="fc7">"red"</span></span>))</span></div><div class="t m6 x38 h2c ya9 ff18 fs1d fc2 sc0 ls0 ws0">Could<span class="_ _20"> </span>b<span class="_ _d"></span>e<span class="_ _20"> </span>done<span class="_ _20"> </span>wi th<span class="_ _1f"> </span>a<span class="_ _20"> </span><span class="ff1a">JOIN?</span></div><div class="t m6 x38 h2c yaa ff18 fs1d fc2 sc0 lsf ws0">Ye<span class="_ _4"></span>s<span class="_ _19"></span>!<span class="_ _19"></span>!</div><div class="t m6 x38 h2d yab ff19 fs1e fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">NameS</span></div><div class="t m6 x38 h2d yac ff19 fs1e fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supplier,<span class="_ _21"> </span>Supply,<span class="_ _21"> </span>Product</span></div><div class="t m6 x38 h2d yad ff19 fs1e fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Supplier.CodeS<span class="fc6">=</span>Supply.CodeS<span class="_ _21"> </span></span>AND<span class="_ _21"> </span><span class="fc2">Supply.CodeP<span class="_ _21"> </span><span class="fc6">=<span class="_ _21"> </span></span>Product.CodeP<span class="_ _21"> </span></span>AND</div><div class="t m6 x3b h2d yae ff19 fs1e fc2 sc0 ls0 ws0">Product.CodeP<span class="_ _21"> </span><span class="fc6">=<span class="_ _21"> </span><span class="fc7">"P2"</span></span></div><div class="t m6 x3c h2e yaf ff1b fs1f fc1 sc0 ls10 ws0">Advanced<span class="_ _1a"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _22"> </span>37<span class="_ _1a"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-2" class="step pf w0 h0" data-x="4000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the name of artists that played neither rock nor pop songs. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.2 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the name of artists that played neither rock nor pop songs. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT DISTINCT Artist.Name
FROM Artist JOIN Album ON Album.ArtistId =
Artist.ArtistId
WHERE Artist.ArtistId NOT IN (
SELECT Album.ArtistId
FROM Track JOIN Album ON Album.AlbumId =
Track.AlbumId
WHERE GenreId = 1 OR GenreId = 6
)</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pfa" class="step pf w0 h0" data-x="4500" data-y="0" data-scale="0.4" data-page-no="a"><div class="pc pca w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bga.png"/><div class="t m0 x5 h11 y3a ff3 fsa fc2 sc0 ls0 ws0">Nested Queries <span class="_ _23"></span>That Return One <span class="_ _23"></span>T<span class="_ _24"></span>uple</div><div class="t m0 x6 h8 yb2 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 yb3 ff2 fs0 fc2 sc0 ls0 ws0">If a subquer<span class="_ _9"></span>y is guaranteed to pr<span class="_ _0"></span>oduce one tuple, then the r<span class="_ _0"></span>esult </div><div class="t m0 x9 h1 yb4 ff2 fs0 fc2 sc0 ls0 ws0">of the subquer<span class="_ _9"></span>y <span class="ff1 ls11">can be used as a value</span> </div><div class="t m0 x16 h8 yb5 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x3d h2 yb6 ff2 fs0 fc2 sc0 ls0 ws0">T<span class="_ _a"></span>ypically<span class="_ _6"></span>, a single tuple is guaranteed by key constraints of </div><div class="t m0 x3d h2 yb7 ff2 fs0 fc2 sc0 ls0 ws0">attributes <span class="ff5 ls12">SELECT</span>ed by the subquer<span class="_ _9"></span>y </div><div class="t m0 x6 h8 yb8 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 yb9 ff2 fs0 fc2 sc0 ls0 ws0">A run-time err<span class="_ _0"></span>or occurs if ther<span class="_ _0"></span>e is no tuple or mor<span class="_ _0"></span>e than one tuple </div><div class="t m0 x6 h8 yba ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 ybb ff2 fs0 fc2 sc0 ls0 ws0">Usually<span class="_ _6"></span>, the tuple has one attribute, but with a tuple constructor </div><div class="t m0 x9 h1 ybc ff2 fs0 fc2 sc0 ls0 ws0">we might have many => <span class="ff1 ls11">row subquery</span></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">10</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pfb" class="step pf w0 h0" data-x="5000" data-y="0" data-scale="0.4" data-page-no="b"><div class="pc pcb w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bgb.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /1</div><div class="c xa ybd wc h2f"><div class="t m0 x3f h31 ybe ff2 fs21 fc2 sc0 ls0 ws0">Find the code of suppliers having their of<span class="_ _0"></span>fice in the same city as <span class="ff5 ls13">S1</span> </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">11</div><div class="c x1b y50 w4 h12"><div class="t m0 x1c h2 y51 ff2 fs0 fc2 sc0 ls0 ws0">With Join</div></div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c xb ybf w9 h32"><div class="t m7 x28 h33 yc0 ff1c fs22 fc4 sc0 ls0 ws0">Example<span class="_ _14"> </span>/1</div><div class="t m7 x23 h34 yc1 ff1d fs23 fc2 sc0 ls0 ws0">Find<span class="_ _c"> </span>the<span class="_ _25"> </span>co<span class="_ _d"></span>de<span class="_ _25"> </span>of<span class="_ _25"> </span>suppl i er s<span class="_ _c"> </span>having<span class="_ _25"> </span>the i r<span class="_ _c"> </span>o<span class="ff1e">ffi</span><span class="ls14">ce<span class="_ _25"> </span>in<span class="_ _25"> </span>the<span class="_ _c"> </span>same<span class="_ _25"> </span>cit<span class="_ _5"></span>y<span class="_ _c"> </span>as</span></div><div class="t m7 x23 h34 yc2 ff1d fs23 fc2 sc0 ls15 ws0">S1</div><div class="t m7 x40 h35 yc3 ff1f fs24 fc5 sc0 ls0 ws0">SELECT<span class="_ _10"> </span><span class="fc2">CodeS</span></div><div class="t m7 x40 h35 yc4 ff1f fs24 fc5 sc0 ls0 ws0">FROM<span class="_ _10"> </span><span class="fc2">Supplier</span></div><div class="t m7 x40 h35 yc5 ff1f fs24 fc5 sc0 ls0 ws0">WHERE<span class="_ _10"> </span><span class="fc2">Office<span class="_ _26"> </span><span class="fc6">=<span class="_ _26"> </span></span>(</span>SELECT<span class="_ _10"> </span><span class="fc2">Office</span></div><div class="t m7 x41 h35 yc6 ff1f fs24 fc5 sc0 ls0 ws0">FROM<span class="_ _26"> </span><span class="fc2">Supplier</span></div><div class="t m7 x41 h35 yc7 ff1f fs24 fc5 sc0 ls0 ws0">WHERE<span class="_ _26"> </span><span class="fc2">CodeS<span class="_ _10"> </span><span class="fc6">=<span class="_ _26"> </span><span class="fc7">"S1"</span></span>)</span></div><div class="t m7 x23 h34 yc8 ff1d fs23 fc2 sc0 ls0 ws0">Could<span class="_ _25"> </span>b<span class="_ _d"></span>e<span class="_ _25"> </span>done<span class="_ _c"> </span>with<span class="_ _25"> </span>a<span class="_ _c"> </span><span class="ff20">JOIN?</span></div><div class="t m7 x23 h34 yc9 ff1d fs23 fc2 sc0 ls16 ws0">Ye<span class="_ _11"></span>s<span class="_ _27"></span>!<span class="_ _11"></span>!</div><div class="t m7 x23 h35 yca ff1f fs24 fc5 sc0 ls0 ws0">SELECT<span class="_ _26"> </span><span class="fc2">CodeS</span></div><div class="t m7 x23 h35 ycb ff1f fs24 fc5 sc0 ls0 ws0">FROM<span class="_ _26"> </span><span class="fc2">Supplier<span class="_ _10"> </span></span>AS<span class="_ _26"> </span><span class="fc2">Su1,<span class="_ _10"> </span>Supplier<span class="_ _26"> </span></span>AS<span class="_ _10"> </span><span class="fc2">Su2</span></div><div class="t m7 x23 h35 ycc ff1f fs24 fc5 sc0 ls0 ws0">WHERE<span class="_ _26"> </span><span class="fc2">Su1.Office<span class="fc6">=</span>Su2.Office<span class="_ _10"> </span></span>AND<span class="_ _26"> </span><span class="fc2">Su1.CodeS<span class="_ _10"> </span><span class="fc6">=<span class="_ _26"> </span><span class="fc7">"S1"</span></span></span></div><div class="t m7 x42 h36 ycd ff21 fs25 fc1 sc0 ls17 ws0">Advanced<span class="_ _1a"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _28"> </span>33<span class="_ _1a"> </span>/<span class="_ _1a"> </span>74</div></div><div class="c x1b y54 w6 h12"><div class="t m0 x1f h2 y55 ff2 fs0 fc2 sc0 ls0 ws0">With Nested Queries</div></div><div class="c x2d yce wd h37"><div class="t m8 x43 h38 ycf ff22 fs26 fc4 sc0 ls0 ws0">Example<span class="_ _29"> </span>/1</div><div class="t m8 x13 h39 yd0 ff23 fs27 fc2 sc0 ls0 ws0">Find<span class="_ _e"> </span>the<span class="_ _e"> </span>co<span class="_ _d"></span>de<span class="_ _e"> </span>of<span class="_ _e"> </span>suppli e rs<span class="_ _f"> </span>having<span class="_ _e"> </span>their<span class="_ _e"> </span>o<span class="ff24">ffi </span><span class="ls18">ce<span class="_ _e"> </span>i n<span class="_ _f"> </span>the<span class="_ _e"> </span>same<span class="_ _e"> </span>cit<span class="_ _5"></span>y<span class="_ _e"> </span>as</span></div><div class="t m8 x13 h39 yd1 ff23 fs27 fc2 sc0 ls19 ws0">S1</div><div class="t m8 x23 h3a yd2 ff25 fs28 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">CodeS</span></div><div class="t m8 x23 h3a yd3 ff25 fs28 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supplier</span></div><div class="t m8 x23 h3a yd4 ff25 fs28 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Office<span class="_ _18"> </span><span class="fc6">=<span class="_ _1d"> </span></span>(</span>SELECT<span class="_ _2a"> </span><span class="fc2">Office</span></div><div class="t m8 x44 h3a yd5 ff25 fs28 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supplier</span></div><div class="t m8 x44 h3a yd6 ff25 fs28 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">CodeS<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"S1"</span></span>)</span></div><div class="t m8 x13 h39 yd7 ff23 fs27 fc2 sc0 ls0 ws0">Could<span class="_ _e"> </span>b<span class="_ _d"></span>e<span class="_ _e"> </span>done<span class="_ _e"> </span>with<span class="_ _e"> </span>a<span class="_ _e"> </span><span class="ff26">JOIN?</span></div><div class="t m8 x13 h39 yd8 ff23 fs27 fc2 sc0 ls1a ws0">Ye<span class="_ _11"></span>s<span class="_ _11"></span>!<span class="_ _11"></span>!</div><div class="t m8 x13 h3a yd9 ff25 fs28 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">CodeS</span></div><div class="t m8 x13 h3a yda ff25 fs28 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Supplier<span class="_ _2a"> </span></span>AS<span class="_ _2a"> </span><span class="fc2">Su1,<span class="_ _2a"> </span>Supplier<span class="_ _2a"> </span></span>AS<span class="_ _2a"> </span><span class="fc2">Su2</span></div><div class="t m8 x13 h3a ydb ff25 fs28 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Su1.Office<span class="fc6">=</span>Su2.Office<span class="_ _2a"> </span></span>AND<span class="_ _2a"> </span><span class="fc2">Su1.CodeS<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"S1"</span></span></span></div><div class="t m8 x3 h3b ydc ff27 fs29 fc1 sc0 ls1b ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _2c"> </span>33<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pfc" class="step pf w0 h0" data-x="5500" data-y="0" data-scale="0.4" data-page-no="c"><div class="pc pcc w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bgc.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /2</div><div class="c xa y4d w1 h9"><div class="t m0 xa ha y4e ff2 fs6 fc2 sc0 ls0 ws0">Find the code of suppliers with less shar<span class="_ _0"></span>eholders than the supplier </div><div class="t m0 x45 ha y4f ff2 fs6 fc2 sc0 ls0 ws0">having the maximum number of shar<span class="_ _0"></span>eholders </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">12</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c x46 ydd w6 h12"><div class="t m0 x1f h2 yde ff2 fs0 fc2 sc0 ls0 ws0">With Nested Queries</div></div><div class="c xb ydf we h11"><div class="t m9 x47 h3c ye0 ff28 fs2a fc4 sc0 ls0 ws0">Example<span class="_ _2d"> </span>/2</div><div class="t m9 x15 h3d ye1 ff29 fs2b fc2 sc0 ls0 ws0">Find<span class="_ _16"> </span>the<span class="_ _16"> </span>co<span class="_ _d"></span>de<span class="_ _16"> </span>of<span class="_ _16"> </span>suppliers<span class="_ _16"> </span>with<span class="_ _16"> </span>less<span class="_ _16"> </span>sha<span class="_ _5"></span>reholder s<span class="_ _16"> </span>than<span class="_ _16"> </span>the<span class="_ _16"> </span>suppli e r</div><div class="t m9 x15 h3d ye2 ff29 fs2b fc2 sc0 ls0 ws0">having<span class="_ _f"> </span>the<span class="_ _e"> </span>ma xi mu m<span class="_ _f"> </span>numb<span class="_ _d"></span>er<span class="_ _f"> </span>of<span class="_ _e"> </span>s ha<span class="_ _0"></span>reholders</div><div class="t m9 x23 h3e ye3 ff2a fs2c fc5 sc0 ls0 ws0">SELECT<span class="_ _2a"> </span><span class="fc2">CodeS</span></div><div class="t m9 x23 h3e ye4 ff2a fs2c fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Supplier</span></div><div class="t m9 x23 h3e ye5 ff2a fs2c fc5 sc0 ls0 ws0">WHERE<span class="_ _2a"> </span><span class="fc2">Shareholders<span class="_ _18"> </span><span class="fc6"><<span class="_ _2a"> </span></span>(</span>SELECT<span class="_ _18"> </span><span class="fc8">Max<span class="fc2">(Shareholders)</span></span></div><div class="t m9 x48 h3e ye6 ff2a fs2c fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Supplier)</span></div><div class="t m9 x15 h3d ye7 ff29 fs2b fc2 sc0 ls0 ws0">Could<span class="_ _e"> </span>b<span class="_ _d"></span>e<span class="_ _f"> </span>done<span class="_ _f"> </span>with<span class="_ _f"> </span>a<span class="_ _e"> </span><span class="ff2b">JOIN?</span></div><div class="t m9 x15 h3d ye8 ff29 fs2b fc2 sc0 ls0 ws0">Ma<span class="_ _5"></span>yb<span class="_ _d"></span>e.<span class="_ _18"> </span>T h in k<span class="_ _f"> </span>ab<span class="_ _d"></span>out<span class="_ _f"> </span>it<span class="_ _f"> </span>:)</div><div class="t m9 x49 h3f ye9 ff2c fs2d fc1 sc0 ls1c ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _2e"> </span>34<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div><div class="c x46 yea w4 h12"><div class="t m0 x2c h2 yeb ff2 fs0 fc2 sc0 ls0 ws0">With Join??</div></div><div class="c x4a yec wf h40"><div class="t m0 x4b h41 yed ff2 fs2e fc1 sc0 ls0 ws0">Maybe. Think about it :)</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pfd" class="step pf w0 h0" data-x="6000" data-y="0" data-scale="0.4" data-page-no="d"><div class="pc pcd w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bgd.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /3</div><div class="c xa y4d w1 h9"><div class="t m0 x12 ha y4e ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers that supply at least one pr<span class="_ _0"></span>oduct </div><div class="t m0 x4c ha y4f ff2 fs6 fc2 sc0 ls0 ws0">supplied by suppliers of r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts</div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">13</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c x4a yee w10 h42"><div class="t m0 xe h43 yef ff1 fs2f fc1 sc0 ls0 ws0">Difficult to express with joins </div><div class="t m0 xe h44 yf0 ff2 fs30 fc1 sc0 ls0 ws0">•</div><div class="t m0 xb h45 yf1 ff2 fs2f fc1 sc0 ls0 ws0">Code of r<span class="_ _0"></span>ed pr<span class="_ _2f"></span>oducts </div><div class="t m0 xe h44 yf2 ff2 fs30 fc1 sc0 ls0 ws0">•</div><div class="t m0 xb h45 yf3 ff2 fs2f fc1 sc0 ls0 ws0">Code of suppliers that supply such pr<span class="_ _0"></span>oducts </div><div class="t m0 xe h44 yf4 ff2 fs30 fc1 sc0 ls0 ws0">•</div><div class="t m0 xb h45 yf5 ff2 fs2f fc1 sc0 ls0 ws0">Code of pr<span class="_ _0"></span>oducts supplied by suppliers of r<span class="_ _2f"></span>ed pr<span class="_ _0"></span>oducts </div><div class="t m0 xe h44 yf6 ff2 fs30 fc1 sc0 ls0 ws0">•</div><div class="t m0 xb h45 yf7 ff2 fs2f fc1 sc0 ls0 ws0">Code of the suppliers of the pr<span class="_ _0"></span>oducts supplied by suppliers of r<span class="_ _2f"></span>ed pr<span class="_ _0"></span>oducts </div><div class="t m0 xe h44 yf8 ff2 fs30 fc1 sc0 ls0 ws0">•</div><div class="t m0 xb h45 yf9 ff2 fs2f fc1 sc0 ls0 ws0">Name of such suppliers </div></div><div class="c x4d yfa w11 h46"><div class="t ma x0 h47 yfb ff2d fs31 fc4 sc0 ls0 ws0">Example<span class="_ _30"> </span>/3</div><div class="t ma x1c h48 yfc ff2e fs32 fc2 sc0 ls0 ws0">Find<span class="_ _20"> </span>the<span class="_ _1f"> </span>name<span class="_ _1f"> </span>of<span class="_ _20"> </span>the<span class="_ _1f"> </span>suppliers<span class="_ _1f"> </span>that<span class="_ _20"> </span>s up p l y<span class="_ _1f"> </span>at<span class="_ _1f"> </span>least<span class="_ _20"> </span>one<span class="_ _1f"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>duct<span class="_ _1f"> </span>supplied<span class="_ _1f"> </span>b<span class="_ _0"></span>y</div><div class="t ma x1c h48 yfd ff2e fs32 fc2 sc0 ls0 ws0">suppliers<span class="_ _1f"> </span>of<span class="_ _20"> </span>red<span class="_ _1f"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts</div><div class="t ma x1c h48 yfe ff2e fs32 fc2 sc0 ls1d ws0">Di<span class="ff2f ls0">ffi<span class="ff2e">cult<span class="_ _20"> </span>to<span class="_ _1f"> </span>exp<span class="_ _0"></span>ress<span class="_ _20"> </span>with<span class="_ _1f"> </span>joins</span></span></div><div class="t ma x24 h49 yff ff2e fs33 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _31"> </span>of<span class="_ _31"> </span>red<span class="_ _31"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts</div><div class="t ma x24 h49 y100 ff2e fs33 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _31"> </span>of<span class="_ _31"> </span>suppliers<span class="_ _31"> </span>that<span class="_ _31"> </span>supply<span class="_ _31"> </span>such<span class="_ _31"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts</div><div class="t ma x24 h49 y101 ff2e fs33 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _31"> </span>of<span class="_ _31"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts<span class="_ _31"> </span>supplied<span class="_ _31"> </span>b<span class="_ _0"></span>y<span class="_ _31"> </span>suppliers<span class="_ _31"> </span>of<span class="_ _32"> </span>red<span class="_ _32"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>du cts</div><div class="t ma x24 h49 y102 ff2e fs33 fc2 sc0 ls0 ws0">Co<span class="_ _9"></span>de<span class="_ _31"> </span>of<span class="_ _32"> </span>the<span class="_ _31"> </span>suppliers<span class="_ _31"> </span>of<span class="_ _31"> </span>the<span class="_ _31"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts<span class="_ _32"> </span>s up p l ie d<span class="_ _31"> </span>b<span class="_ _0"></span>y<span class="_ _31"> </span>suppliers<span class="_ _31"> </span>of<span class="_ _32"> </span>red<span class="_ _31"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts</div><div class="t ma x24 h49 y103 ff2e fs33 fc2 sc0 ls0 ws0">Name<span class="_ _32"> </span>of<span class="_ _31"> </span>such<span class="_ _31"> </span>suppliers</div><div class="t ma x4e h4a y104 ff30 fs34 fc5 sc0 ls1e ws0">SELECT<span class="_ _16"> </span><span class="fc2">NameS</span></div><div class="t ma x4e h4a y105 ff30 fs34 fc5 sc0 ls1e ws0">FROM<span class="_ _16"> </span><span class="fc2">Supplier</span></div><div class="t ma x4e h4a y106 ff30 fs34 fc5 sc0 ls1e ws0">WHERE<span class="_ _16"> </span><span class="fc2">CodeS<span class="_ _e"> </span></span>IN<span class="_ _16"> </span><span class="fc2 ls0">(</span>SELECT<span class="_ _e"> </span><span class="fc2">CodeS</span></div><div class="t ma xd h4a y107 ff30 fs34 fc5 sc0 ls1e ws0">FROM<span class="_ _16"> </span><span class="fc2">Supply</span></div><div class="t ma xd h4a y108 ff30 fs34 fc5 sc0 ls1e ws0">WHERE<span class="_ _16"> </span><span class="fc2">CodeP<span class="_ _e"> </span></span>IN<span class="fc2 ls0">(<span class="_ _16"> </span></span>SELECT<span class="_ _e"> </span><span class="fc2">CodeP</span></div><div class="t ma x4f h4a y109 ff30 fs34 fc5 sc0 ls1e ws0">FROM<span class="_ _16"> </span><span class="fc2">Supply</span></div><div class="t ma x4f h4a y10a ff30 fs34 fc5 sc0 ls1e ws0">WHERE<span class="_ _16"> </span><span class="fc2">CodeS<span class="_ _e"> </span></span>IN<span class="_ _16"> </span><span class="fc2 ls0">(</span>SELECT<span class="_ _e"> </span><span class="fc2">CodeS</span></div><div class="t ma x50 h4a y10b ff30 fs34 fc5 sc0 ls1e ws0">FROM<span class="_ _16"> </span><span class="fc2">Supply</span></div><div class="t ma x50 h4a y10c ff30 fs34 fc5 sc0 ls1e ws0">WHERE<span class="_ _16"> </span><span class="fc2">CodeP<span class="_ _e"> </span></span>IN<span class="_ _16"> </span><span class="fc2 ls0">(<span class="_ _e"> </span></span><span class="ls1f">SELECT<span class="_ _16"> </span><span class="fc2">Code<span class="_ _33"></span>P</span></span></div><div class="t ma x51 h4a y10d ff30 fs34 fc5 sc0 ls1e ws0">FROM<span class="_ _16"> </span><span class="fc2">Product</span></div><div class="t ma x51 h4a y10e ff30 fs34 fc5 sc0 ls1e ws0">WHERE<span class="_ _16"> </span><span class="fc2">Color<span class="_ _e"> </span><span class="fc6 ls0">=<span class="_ _16"> </span></span><span class="fc7">"Red"</span>))))</span></div><div class="t ma x52 h4b y10f ff31 fs35 fc1 sc0 ls20 ws0">Advanced<span class="_ _1a"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _34"> </span>38<span class="_ _1a"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pfe" class="step pf w0 h0" data-x="6500" data-y="0" data-scale="0.4" data-page-no="e"><div class="pc pce w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bge.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example /3 with <span class="ff5 ls21">JOIN</span></div><div class="c xa y110 w1 h9"><div class="t m0 x12 ha y111 ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers that supply at least one pr<span class="_ _0"></span>oduct </div><div class="t m0 x4c ha y112 ff2 fs6 fc2 sc0 ls0 ws0">supplied by suppliers of r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts</div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">14</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="c x20 y11 w12 h4c"><div class="t mb x53 h4d y113 ff32 fs36 fc4 sc0 ls0 ws0">Example<span class="_ _2d"> </span>/3<span class="_ _2d"> </span>with<span class="_ _2d"> </span><span class="ff33 ls22">JOIN</span></div><div class="t mb xe h4e y114 ff34 fs37 fc5 sc0 ls23 ws0">SELECT<span class="_ _21"> </span><span class="fc2">NameS</span></div><div class="t mb xe h4e y115 ff34 fs37 fc5 sc0 ls23 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supplier,<span class="_ _21"> </span>Supply<span class="_ _21"> </span></span>as<span class="_ _21"> </span><span class="fc2">SA,<span class="_ _21"> </span>Supply<span class="_ _21"> </span></span>as<span class="_ _21"> </span><span class="fc2 ls24">SB,<span class="_ _21"> </span>Supply<span class="_ _21"> </span></span>as<span class="_ _21"> </span><span class="fc2">SBC,<span class="_ _21"> </span>Product</span></div><div class="t mb xe h4e y116 ff34 fs37 fc5 sc0 ls23 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Supplier.CodeS<span class="_ _21"> </span><span class="fc6 ls0">=<span class="_ _21"> </span></span>SA.<span style="visibility:hidden; opacity:0;">CodeF</span><span class="_ _21"> </span></span>AND</div><div class="t mb x54 h4e y117 ff34 fs37 fc2 sc0 ls23 ws0">SA.CodeP<span class="_ _21"> </span><span class="fc6 ls0">=<span class="_ _21"> </span></span>SB.CodeP<span class="_ _21"> </span><span class="fc5">AND</span></div><div class="t mb x54 h4e y118 ff34 fs37 fc2 sc0 ls23 ws0">SB.<span style="visibility:hidden; opacity:0;">CodeF</span><span class="_ _21"> </span><span class="fc6 ls0">=<span class="_ _21"> </span></span>SC.<span style="visibility:hidden; opacity:0;">CodeF</span><span class="_ _21"> </span><span class="fc5">AND</span></div><div class="t mb x54 h4e y119 ff34 fs37 fc2 sc0 ls23 ws0">SC.CodeP<span class="_ _21"> </span><span class="fc6 ls0">=<span class="_ _21"> </span></span>Product.CodeP<span class="_ _21"> </span><span class="fc5">AND</span></div><div class="t mb x54 h4e y11a ff34 fs37 fc2 sc0 ls23 ws0">Color<span class="_ _21"> </span><span class="fc6 ls0">=<span class="_ _21"> </span></span><span class="fc7">"Red"</span></div><div class="t mb x55 h4f y11b ff35 fs38 fc1 sc0 ls25 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _35"> </span>39<span class="_ _2b"> </span>/<span class="_ _1a"> </span>74</div></div><div class="c x56 y11c w13 h50"><div class="t m0 xe h51 y11d ff36 fs39 fc2 sc0 ls26 ws0">CodeS</div></div><div class="c x57 y11e w13 h50"><div class="t m0 xe h51 y11f ff36 fs39 fc2 sc0 ls26 ws0">CodeS</div></div><div class="c x35 y11e w13 h50"><div class="t m0 x27 h51 y11f ff36 fs39 fc2 sc0 ls26 ws0">CodeS</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-new" class="step" data-x="7000" data-y="0" data-scale="0.4" data-timer="30">
<asq-exercise style="height: 420px; padding: 20px 20px; background: rgba(255, 255, 255, 0.6); margin-top: 40px;">
<asq-stem class="small"><h4><b>When an SQL query combines three or more AND and OR conditions in the WHERE clause, which of the following SQL operations would you use?</b></h4>
</asq-stem>
<asq-multi-choice-q>
<asq-stem class="hidden"><h4>When an SQL query combines three or more AND and OR conditions in the WHERE clause, which of the following SQL operations would you use?</h4>
</asq-stem>
<asq-option class="smaller" style="display: block;" name="a">LIKE</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="b">IN</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="c">NOT IN</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="d" correct>Both IN and NOT IN</asq-option>
</asq-multi-choice-q>
</asq-exercise>
<div class="flickr-credit">flickr@nasacommons</div>
</div>
<div id="pff" class="step pf w0 h0" data-x="7500" data-y="0" data-scale="0.4" data-page-no="f"><div class="pc pcf w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bgf.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example with <span class="ff5 ls21">NOT IN</span></div><div class="c x4a y120 w14 h2f"><div class="t m0 x4a h2 y121 ff2 fs0 fc2 sc0 ls0 ws0">Find the name of the suppliers that do not supply pr<span class="_ _0"></span>oduct P2 </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">15</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="t m0 x20 h8 y122 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 y123 ff2 fs0 fc2 sc0 ls0 ws0">Can you expr<span class="_ _0"></span>ess it with <span class="ff5 ls12">JOIN</span>?</div><div class="c x20 y124 w15 h15"><div class="t mc x58 h52 y125 ff37 fs3a fc4 sc0 ls0 ws0">Example<span class="_ _36"> </span>with<span class="_ _36"> </span><span class="ff38 ls27">NOT<span class="_ _37"> </span>IN</span></div><div class="t mc x59 h53 y126 ff39 fs3b fc2 sc0 ls0 ws0">Find<span class="_ _c"> </span>the<span class="_ _38"> </span>name<span class="_ _c"> </span>of<span class="_ _38"> </span>the<span class="_ _c"> </span>supplie rs<span class="_ _38"> </span>that<span class="_ _c"> </span>do<span class="_ _38"> </span>not<span class="_ _c"> </span>supply<span class="_ _38"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>duct<span class="_ _c"> </span>P2</div><div class="t mc x59 h53 y127 ff39 fs3b fc2 sc0 ls0 ws0">Can<span class="_ _c"> </span>y<span class="_ _5"></span>ou<span class="_ _38"> </span>exp<span class="_ _5"></span>ress<span class="_ _c"> </span>it<span class="_ _38"> </span>with<span class="_ _c"> </span>a<span class="_ _38"> </span><span class="ff3a">JOIN</span>?</div><div class="t mc x59 h54 y128 ff3b fs3c fc5 sc0 ls0 ws0">SELECT<span class="_ _39"> </span><span class="fc2">NameS</span></div><div class="t mc x59 h54 y129 ff3b fs3c fc5 sc0 ls0 ws0">FROM<span class="_ _39"> </span><span class="fc2">Supplier,<span class="_ _39"> </span>Supply</span></div><div class="t mc x59 h54 y12a ff3b fs3c fc5 sc0 ls0 ws0">WHERE<span class="_ _39"> </span><span class="fc2">Supplier.CodeS<span class="_ _39"> </span><span class="fc6">=<span class="_ _39"> </span></span>Supply.CodeS<span class="_ _39"> </span></span>AND<span class="_ _39"> </span><span class="fc2">CodeP<span class="_ _39"> </span><span class="fc6"><><span class="_ _39"> </span><span class="fc7">"P2"</span></span></span></div><div class="t mc x38 h55 y12b ff39 fs3d fc2 sc0 ls0 ws0">W<span class="_ _5"></span>rong!</div><div class="t mc x38 h55 y12c ff39 fs3d fc2 sc0 ls0 ws0">This<span class="_ _f"> </span>w<span class="_ _5"></span>ould<span class="_ _15"> </span>answ<span class="_ _5"></span>er<span class="_ _f"> </span>the<span class="_ _f"> </span>qu er y:<span class="_ _26"> </span>“Find<span class="_ _f"> </span>the<span class="_ _f"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>the<span class="_ _f"> </span>su p p li e rs</div><div class="t mc x38 h55 y12d ff39 fs3d fc2 sc0 ls0 ws0">that<span class="_ _f"> </span>supply<span class="_ _f"> </span>at<span class="_ _f"> </span>least<span class="_ _f"> </span>on e<span class="_ _15"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>duct<span class="_ _f"> </span>di<span class="ff3c">↵</span>erent<span class="_ _f"> </span>from<span class="_ _15"> </span>P2”</div><div class="t mc x42 h56 y12e ff3d fs3e fc1 sc0 ls28 ws0">Advanced<span class="_ _1a"> </span>SQL<span class="_ _12"> </span>Queries<span class="_ _3a"> </span>40<span class="_ _1a"> </span>/<span class="_ _12"> </span>74</div></div><div class="t m0 x20 h57 y12f ff1 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h1 y130 ff1 fs0 fc2 sc0 ls0 ws0">WRONG!!!</div><div class="t m0 x20 h57 y131 ff1 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h1 y132 ff1 fs0 fc2 sc0 ls0 ws0">This would answer the query: </div><div class="c xa y133 w1 h9"><div class="t m0 xe ha y134 ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers that supply at least one pr<span class="_ _0"></span>oduct dif<span class="_ _0"></span>fer<span class="_ _0"></span>ent </div><div class="t m0 x3a ha y135 ff2 fs6 fc2 sc0 ls0 ws0">fr<span class="_ _0"></span>om P2</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf10" class="step pf w0 h0" data-x="8000" data-y="0" data-scale="0.4" data-page-no="10"><div class="pc pc10 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg10.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example with <span class="ff5 ls21">NOT IN/2</span></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">16</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="t m0 x20 h58 y136 ff2 fs3f fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h30 y7 ff2 fs20 fc2 sc0 ls0 ws0">W<span class="_ _0"></span>e need to exclude fr<span class="_ _0"></span>om the r<span class="_ _0"></span>esult set suppliers that supply P2 </div><div class="c x46 y137 w16 h59"><div class="t md x5a h5a y138 ff3e fs40 fc4 sc0 ls0 ws0">Example<span class="_ _30"> </span>with<span class="_ _2d"> </span><span class="ff3f ls29">NOT<span class="_ _3b"> </span>IN<span class="_ _3c"> </span></span><span class="ls2a">/2</span></div><div class="t md x1c h5b y139 ff40 fs41 fc2 sc0 ls0 ws0">W<span class="_ _5"></span>e<span class="_ _15"> </span>need<span class="_ _f"> </span>to<span class="_ _15"> </span>exclude<span class="_ _15"> </span>from<span class="_ _15"> </span>the<span class="_ _15"> </span>result<span class="_ _15"> </span>set<span class="_ _f"> </span>suppl i er s<span class="_ _15"> </span>that<span class="_ _15"> </span>supply<span class="_ _15"> </span>P2</div><div class="t md x5b h5c y13a ff41 fs42 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t md x5b h5c y13b ff41 fs42 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t md x5b h5c y13c ff41 fs42 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeS<span class="_ _18"> </span></span>NOT<span class="_ _26"> </span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t md x5c h5c y13d ff41 fs42 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t md x5c h5c y13e ff41 fs42 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _18"> </span><span class="fc6">=<span class="_ _26"> </span><span class="fc7">"P2"</span></span>)</span></div><div class="t md x5d h5d y13f ff42 fs43 fc1 sc0 ls2b ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _3d"> </span>41<span class="_ _2b"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf11" class="step pf w0 h0" data-x="8500" data-y="0" data-scale="0.4" data-page-no="11"><div class="pc pc11 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg11.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example with <span class="ff5 ls21">NOT IN /3</span></div><div class="c x4a y120 w14 h2f"><div class="t m0 x2d h2 y121 ff2 fs0 fc2 sc0 ls0 ws0">Find the name of the suppliers that supply ONL<span class="_ _1"></span>Y pr<span class="_ _0"></span>oduct P2 </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">17</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="t m0 x20 h5e y140 ff2 fs44 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h5f y141 ff2 fs45 fc2 sc0 ls0 ws0">W<span class="_ _0"></span>e need to exclude fr<span class="_ _0"></span>om the r<span class="_ _0"></span>esult set suppliers that supply </div><div class="t m0 x54 h5f y142 ff2 fs45 fc2 sc0 ls0 ws0">pr<span class="_ _0"></span>oducts dif<span class="_ _0"></span>fer<span class="_ _0"></span>ent fr<span class="_ _0"></span>om P2 </div><div class="t m0 x20 h5e y143 ff2 fs44 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h5f y144 ff2 fs45 fc2 sc0 ls0 ws0">But only keep the ones that actually supply something </div><div class="c x5e y145 w17 h60"><div class="t me x53 h61 y146 ff43 fs46 fc4 sc0 ls0 ws0">Example<span class="_ _2d"> </span>with<span class="_ _3c"> </span><span class="ff44 ls2c">NOT<span class="_ _3e"> </span>IN<span class="_ _2d"> </span></span><span class="ls2d">/3</span></div><div class="t me x38 h62 y147 ff45 fs47 fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _f"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>th e<span class="_ _15"> </span>suppliers<span class="_ _f"> </span>that<span class="_ _f"> </span>supp l y<span class="_ _25"> </span><span class="ff46 ls2e">ONL<span class="_ _a"></span>Y<span class="_ _c"> </span><span class="ff45 ls2f">pr<span class="_ _d"></span>o<span class="_ _3f"></span>d<span class="_ _d"></span>u<span class="_ _9"></span>c<span class="_ _d"></span>t<span class="_ _c"> </span>P<span class="_ _d"></span>2</span></span></div><div class="t me x38 h62 y148 ff45 fs47 fc2 sc0 ls0 ws0">W<span class="_ _5"></span>e<span class="_ _f"> </span>need<span class="_ _f"> </span>to<span class="_ _f"> </span>excl u d e<span class="_ _15"> </span>from<span class="_ _f"> </span>the<span class="_ _f"> </span>result<span class="_ _f"> </span>set<span class="_ _f"> </span>sup p l i er s<span class="_ _f"> </span>th at<span class="_ _15"> </span>supply</div><div class="t me x38 h62 y149 ff45 fs47 fc2 sc0 ls2f ws0">pr<span class="_ _d"></span>o<span class="_ _3f"></span>d<span class="_ _d"></span>u<span class="_ _9"></span>c<span class="_ _d"></span>t<span class="_ _d"></span>s<span class="_ _c"> </span>d<span class="_ _d"></span>i<span class="_ _9"></span><span class="ff47 ls0">↵<span class="ff45">eren t<span class="_ _15"> </span>from<span class="_ _f"> </span>P2</span></span></div><div class="t me x38 h62 y14a ff45 fs47 fc2 sc0 ls0 ws0">But<span class="_ _f"> </span>only<span class="_ _f"> </span>k<span class="_ _0"></span>eep<span class="_ _e"> </span>the<span class="_ _f"> </span>one s<span class="_ _15"> </span>that<span class="_ _f"> </span>actually<span class="_ _f"> </span>supply<span class="_ _15"> </span>something</div><div class="t me x27 h63 y14b ff48 fs48 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t me x27 h63 y14c ff48 fs48 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t me x27 h63 y14d ff48 fs48 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeS<span class="_ _2a"> </span></span>NOT<span class="_ _18"> </span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _2a"> </span><span class="fc2">CodeS</span></div><div class="t me x5c h63 y14e ff48 fs48 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t me x5c h63 y14f ff48 fs48 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _2a"> </span><span class="fc6"><<span class="_ _18"> </span>><span class="_ _40"> </span><span class="fc7">"P2"</span></span>)</span></div><div class="t me x5f h63 y150 ff48 fs48 fc5 sc0 ls0 ws0">AND<span class="_ _18"> </span><span class="fc2">Supplier.CodeS<span class="_ _2a"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(</span>Select<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t me x60 h63 y151 ff48 fs48 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply)</span></div><div class="t me x49 h64 y152 ff49 fs49 fc1 sc0 ls30 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _41"> </span>42<span class="_ _2b"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf12" class="step pf w0 h0" data-x="9000" data-y="0" data-scale="0.4" data-page-no="12"><div class="pc pc12 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg12.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example with <span class="ff5 ls21">NOT IN /4</span></div><div class="c x4a y120 w14 h2f"><div class="t m0 x61 h2 y121 ff2 fs0 fc2 sc0 ls0 ws0">Find the name of the suppliers that DO NOT supply r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts</div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">18</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div><div class="t m0 x20 h65 y153 ff2 fs4a fc2 sc0 ls0 ws0">•</div><div class="t m0 x10 h66 y154 ff2 fs4b fc2 sc0 ls0 ws0">W<span class="_ _0"></span>e need to exclude fr<span class="_ _5"></span>om the r<span class="_ _0"></span>esult set suppliers of </div><div class="t m0 x10 h66 y155 ff2 fs4b fc2 sc0 ls0 ws0">r<span class="_ _0"></span>ed pr<span class="_ _5"></span>oducts </div><div class="c x1b y156 w18 h67"><div class="t mf x62 h68 y157 ff4a fs4c fc4 sc0 ls0 ws0">Example<span class="_ _3c"> </span>with<span class="_ _2d"> </span><span class="ff4b ls31">NOT<span class="_ _42"> </span>IN<span class="_ _2d"> </span></span><span class="ls32">/4</span></div><div class="t mf x9 h69 y158 ff4c fs4d fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _f"> </span>n am e<span class="_ _15"> </span>of<span class="_ _f"> </span>the<span class="_ _f"> </span>suppl i er s<span class="_ _15"> </span>that<span class="_ _f"> </span><span class="ff4d ls33">DO<span class="_ _38"> </span>NOT<span class="_ _f"> </span></span><span class="ls34">supply<span class="_ _f"> </span>red</span></div><div class="t mf x9 h69 y159 ff4c fs4d fc2 sc0 ls35 ws0">pr<span class="_ _d"></span>o<span class="_ _3f"></span>d<span class="_ _d"></span>u<span class="_ _9"></span>c<span class="_ _d"></span>t<span class="_ _d"></span>s</div><div class="t mf x9 h69 y15a ff4c fs4d fc2 sc0 ls0 ws0">W<span class="_ _5"></span>e<span class="_ _f"> </span>need<span class="_ _15"> </span>to<span class="_ _f"> </span>exclude<span class="_ _f"> </span>f r om<span class="_ _15"> </span>the<span class="_ _f"> </span>result<span class="_ _f"> </span>se t<span class="_ _15"> </span>suppliers<span class="_ _f"> </span>of<span class="_ _15"> </span>red<span class="_ _f"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts</div><div class="t mf x31 h6a y15b ff4e fs4e fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t mf x31 h6a y15c ff4e fs4e fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t mf x31 h6a y15d ff4e fs4e fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeS<span class="_ _18"> </span></span>NOT<span class="_ _18"> </span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _2a"> </span></span>SELECT<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t mf x63 h6a y15e ff4e fs4e fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t mf x63 h6a y15f ff4e fs4e fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _18"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _2a"> </span><span class="fc2">CodeP</span></div><div class="t mf x64 h6a y160 ff4e fs4e fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Product</span></div><div class="t mf x64 h6a y161 ff4e fs4e fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Colour<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"Red"</span></span>))</span></div><div class="t mf x1 h6b y162 ff4f fs4f fc1 sc0 ls36 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _43"> </span>43<span class="_ _2b"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-3" class="step pf w0 h0" data-x="9500" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the names of customers who live in the same city as the top employee (The one not managed by anyone). <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.3 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the names of customers who live in the same city as the top employee (The one not managed by anyone). <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT firstname, lastname
FROM customer
WHERE city =
(SELECT city
FROM employee
WHERE reportsTo IS NULL);</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf15" class="step pf w0 h0" data-x="10000" data-y="0" data-scale="0.4" data-page-no="15"><div class="pc pc15 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg15.png"/><div class="t m0 x20 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Scope of <span class="_ _23"></span>Attributes,<span class="_ _44"></span> <span class="_ _45"></span>V<span class="_ _7"></span>ariables,<span class="_ _23"></span> </div><div class="t m0 x20 h4 y16d ff3 fs2 fc2 sc0 ls0 ws0">and cor<span class="_ _0"></span>r<span class="_ _3"></span>elated queries </div><div class="t m0 x69 h6d y16e ff2 fs50 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h6e y16f ff2 fs51 fc2 sc0 ls0 ws0">A subquer<span class="_ _9"></span>y can use attributes and/or variables defined </div><div class="t m0 x54 h6e y170 ff2 fs51 fc2 sc0 ls0 ws0">by outer<span class="_ _9"></span>most queries in their WHERE clause </div><div class="t m0 x10 h6d y171 ff2 fs50 fc2 sc0 ls0 ws0">•</div><div class="t m0 x18 h6e y172 ff2 fs51 fc2 sc0 ls0 ws0">this is sometimes r<span class="_ _0"></span>eferr<span class="_ _0"></span>ed to as “transfer of bindings” </div><div class="t m0 x69 h6d y173 ff2 fs50 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h6e y45 ff2 fs51 fc2 sc0 ls0 ws0">The two queries ar<span class="_ _0"></span>e said to be corr<span class="_ _0"></span>elated </div><div class="t m0 x69 h6d y174 ff2 fs50 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h6f y175 ff2 fs51 fc2 sc0 ls0 ws0">Semantics: the nested quer<span class="_ _9"></span>y is evaluated <span class="ff1">for each row </span></div><div class="t m0 x54 h6f y176 ff1 fs51 fc2 sc0 ls0 ws0">of the external query<span class="ff2"> </span></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">21</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf16" class="step pf w0 h0" data-x="10500" data-y="0" data-scale="0.4" data-page-no="16"><div class="pc pc16 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg16.png"/><div class="t m0 x5 h11 y3a ff3 fsa fc2 sc0 ls0 ws0">The <span class="ff5 ls5">EXISTS</span> Operator/1</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">22</div><div class="c xa y177 w19 h2f"><div class="t m0 x23 h70 y178 ff2 fs52 fc2 sc0 ls0 ws0">Find the name of the suppliers for whom it exists at least one supply of P2</div></div><div class="c x1b y179 w1a h71"><div class="t m10 x43 h72 y17a ff50 fs53 fc4 sc0 ls0 ws0">Example<span class="_ _29"> </span><span class="ff51">of<span class="_ _46"> </span><span class="ff52 ls37">EXISTS<span class="_ _29"> </span></span>op<span class="_ _3f"></span>erato<span class="_ _47"></span>r</span></div><div class="t m10 x15 h73 y17b ff53 fs54 fc2 sc0 ls0 ws0">“Find<span class="_ _f"> </span>the<span class="_ _f"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>the<span class="_ _f"> </span>suppl i er s<span class="_ _f"> </span>of<span class="_ _f"> </span>P2”</div><div class="t m10 x15 h73 y17c ff53 fs54 fc2 sc0 ls0 ws0">Also:<span class="_ _26"> </span>“Find<span class="_ _e"> </span>the<span class="_ _f"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>the<span class="_ _f"> </span>su pp l i er s<span class="_ _f"> </span>fo<span class="_ _0"></span>r<span class="_ _e"> </span>wh om<span class="_ _f"> </span>i t<span class="_ _f"> </span>exi s ts<span class="_ _f"> </span>at<span class="_ _f"> </span>lea st</div><div class="t m10 x15 h73 y17d ff53 fs54 fc2 sc0 ls0 ws0">one<span class="_ _f"> </span>supply<span class="_ _f"> </span>of<span class="_ _f"> </span>P2”</div><div class="t m10 x23 h74 y17e ff54 fs55 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t m10 x23 h74 y17f ff54 fs55 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t m10 x23 h74 y180 ff54 fs55 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span>EXISTS<span class="_ _2a"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _18"> </span><span class="fc6">*</span></div><div class="t m10 x6a h74 y181 ff54 fs55 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t m10 x6a h74 y182 ff54 fs55 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _2a"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"P2"<span class="_ _18"> </span></span></span></span>AND<span class="_ _2a"> </span><span class="fc2">Supplier.CodeS<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span></span>Supply.CodeS)</span></div><div class="t m10 x15 h73 y183 ff51 fs54 fc2 sc0 ls38 ws0">!!!!<span class="_ _48"> </span><span class="ff53 ls0">W<span class="_ _5"></span>e<span class="_ _f"> </span>need<span class="_ _f"> </span>to<span class="_ _f"> </span>test<span class="_ _f"> </span>the<span class="_ _f"> </span>existe nc e<span class="_ _f"> </span>of<span class="_ _f"> </span>a<span class="_ _f"> </span>su pp l y<span class="_ _f"> </span>fo<span class="_ _0"></span>r<span class="_ _e"> </span>th e<span class="_ _f"> </span>eval u at e</span></div><div class="t m10 x15 h73 y184 ff53 fs54 fc2 sc0 ls39 ws0">suppliers</div><div class="t m10 x15 h73 y185 ff55 fs54 fc2 sc0 ls0 ws0">Suppliers.CodeS<span class="_ _49"> </span>=<span class="_ _49"> </span>Supply.CodeS<span class="_ _e"> </span><span class="ff53">i m p<span class="_ _d"></span>ose<span class="_ _f"> </span>a<span class="_ _f"> </span>co<span class="_ _0"></span>rrelation</span></div><div class="t m10 x15 h73 y186 ff53 fs54 fc2 sc0 ls3a ws0">be<span class="_ _5"></span>t<span class="_ _47"></span>w<span class="_ _47"></span>e<span class="_ _5"></span>e<span class="_ _0"></span>n<span class="_ _17"> </span>e<span class="_ _5"></span>x<span class="_ _5"></span>t<span class="_ _0"></span>e<span class="_ _5"></span>r<span class="_ _5"></span>n<span class="_ _5"></span>a<span class="_ _0"></span>l<span class="_ _17"> </span>a<span class="_ _5"></span>n<span class="_ _5"></span>d<span class="_ _16"> </span>i<span class="_ _5"></span>n<span class="_ _5"></span>t<span class="_ _5"></span>e<span class="_ _5"></span>r<span class="_ _0"></span>n<span class="_ _5"></span>a<span class="_ _5"></span>l<span class="_ _16"> </span>q<span class="_ _5"></span>u<span class="_ _5"></span>e<span class="_ _5"></span>r<span class="_ _5"></span>y</div><div class="t m10 x56 h75 y187 ff56 fs56 fc1 sc0 ls3b ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _35"> </span>45<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div><div class="t m0 x20 h8 y188 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 y189 ff2 fs0 fc2 sc0 ls0 ws0">!!! W<span class="_ _0"></span>e need to test the existence of a <span class="ff6">supply</span> for the evaluation </div><div class="t m0 x9 h2 y18a ff2 fs0 fc2 sc0 ls0 ws0">of <span class="ff6">suppliers</span> </div><div class="t m0 x20 h8 y18b ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 y18c ff5 fs0 fc2 sc0 ls12 ws0">Suppliers.CodeS = Supply.CodeS<span class="ff2 ls0"> imposes a corr<span class="_ _0"></span>elation </span></div><div class="t m0 x9 h2 y18d ff2 fs0 fc2 sc0 ls0 ws0">between exter<span class="_ _9"></span>nal and inter<span class="_ _9"></span>nal quer<span class="_ _9"></span>y </div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB2</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf17" class="step pf w0 h0" data-x="11000" data-y="0" data-scale="0.4" data-page-no="17"><div class="pc pc17 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg17.png"/><div class="t m0 x5 h11 y3a ff3 fsa fc2 sc0 ls0 ws0">The <span class="ff5 ls5">EXISTS</span> Operator /2</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">23</div><div class="c xa y18e w1 h9"><div class="t m0 x61 ha y18f ff2 fs6 fc2 sc0 ls0 ws0">Find all the homonyms, i.e., persons who have the same first name and </div><div class="t m0 x63 ha y190 ff2 fs6 fc2 sc0 ls0 ws0">sur<span class="_ _9"></span>name, but dif<span class="_ _0"></span>fer<span class="_ _0"></span>ent BSN</div></div><div class="c xf y191 w1b h76"><div class="t m11 x47 h77 y192 ff57 fs57 fc4 sc0 ls0 ws0">Scop<span class="_ _3f"></span>e<span class="_ _4a"> </span>of<span class="_ _4a"> </span>A<span class="_ _3"></span>ttribute s<span class="_ _29"> </span>and<span class="_ _4a"> </span>V<span class="_ _4b"></span>ariables</div><div class="t m11 x6b h78 y193 ff58 fs58 fc2 sc0 ls0 ws0">A<span class="_ _1c"> </span>sub<span class="_ _9"></span>qu er y<span class="_ _1c"> </span>can<span class="_ _17"> </span>use<span class="_ _1c"> </span>attributes<span class="_ _1c"> </span>and/o<span class="_ _0"></span>r<span class="_ _1c"> </span>va<span class="_ _5"></span>riab l es<span class="_ _1c"> </span>defi ne d<span class="_ _1c"> </span>b<span class="_ _0"></span>y<span class="_ _1c"> </span>outermost</div><div class="t m11 x6b h78 y194 ff58 fs58 fc2 sc0 ls0 ws0">queries<span class="_ _1c"> </span>(“transfer<span class="_ _1c"> </span>of<span class="_ _1c"> </span>bi n di n gs”)</div><div class="t m11 x6b h78 y195 ff59 fs58 fc2 sc0 ls0 ws0">Semantics<span class="ff58">:<span class="_ _21"> </span>the<span class="_ _1c"> </span>nested<span class="_ _1c"> </span>query<span class="_ _1c"> </span>is<span class="_ _1c"> </span>eval u ate d<span class="_ _1c"> </span>fo<span class="_ _0"></span>r<span class="_ _1c"> </span>each<span class="_ _1c"> </span>ro<span class="_ _0"></span>w<span class="_ _1c"> </span>of<span class="_ _1c"> </span>the<span class="_ _1c"> </span>external</span></div><div class="t m11 x6b h78 y196 ff58 fs58 fc2 sc0 ls3c ws0">query</div><div class="t m11 x6b h78 y197 ff58 fs58 fc2 sc0 ls0 ws0">A<span class="_ _1c"> </span>query<span class="_ _1c"> </span>cannot<span class="_ _1c"> </span>refer<span class="_ _1c"> </span>to<span class="_ _1c"> </span>attribute s<span class="_ _1c"> </span>i n<span class="_ _1c"> </span>a<span class="_ _1c"> </span>su b<span class="_ _d"></span>query<span class="_ _8"></span>,<span class="_ _1f"> </span>o<span class="_ _0"></span>r<span class="_ _1c"> </span>in<span class="_ _1c"> </span>a<span class="_ _1c"> </span>query<span class="_ _1c"> </span>at<span class="_ _1c"> </span>the</div><div class="t m11 x6b h78 y198 ff58 fs58 fc2 sc0 ls0 ws0">same<span class="_ _1c"> </span>level<span class="_ _1c"> </span>of<span class="_ _1c"> </span>nesting</div><div class="t m11 x6b h78 y199 ff58 fs58 fc2 sc0 ls0 ws0">Example:<span class="_ _21"> </span>Find<span class="_ _1c"> </span>all<span class="_ _1c"> </span>the<span class="_ _1c"> </span>homonyms,<span class="_ _17"> </span>i.e.,<span class="_ _1c"> </span>p<span class="_ _9"></span>ers ons<span class="_ _1c"> </span>wh o<span class="_ _1c"> </span>have<span class="_ _17"> </span>the<span class="_ _1c"> </span>same<span class="_ _1c"> </span>first</div><div class="t m11 x6b h78 y19a ff58 fs58 fc2 sc0 ls3c ws0">name<span class="_ _1c"> </span>and<span class="_ _1c"> </span>surname,<span class="_ _1c"> </span>but<span class="_ _1c"> </span>di<span class="ff5a ls0">↵</span>erent<span class="_ _1f"> </span>BSN</div><div class="t m11 x23 h79 y19b ff5b fs59 fc5 sc0 ls0 ws0">SELECT<span class="_ _38"> </span><span class="fc6">*</span></div><div class="t m11 x23 h79 y19c ff5b fs59 fc5 sc0 ls0 ws0">FROM<span class="_ _38"> </span><span class="fc2">Person<span class="_ _38"> </span>P</span></div><div class="t m11 x23 h79 y19d ff5b fs59 fc5 sc0 ls0 ws0">WHERE<span class="_ _38"> </span>EXISTS<span class="_ _38"> </span><span class="fc2">(</span>SELECT<span class="_ _38"> </span><span class="fc6">*</span></div><div class="t m11 x65 h79 y19e ff5b fs59 fc5 sc0 ls0 ws0">FROM<span class="_ _38"> </span><span class="fc2">Person<span class="_ _38"> </span>P1</span></div><div class="t m11 x65 h79 y19f ff5b fs59 fc5 sc0 ls0 ws0">WHERE<span class="_ _38"> </span><span class="fc2">P1.FirstName<span class="_ _38"> </span><span class="fc6">=<span class="_ _38"> </span></span>P.FirstName</span></div><div class="t m11 x6c h79 y1a0 ff5b fs59 fc5 sc0 ls0 ws0">AND<span class="_ _38"> </span><span class="fc2">P1.Surname<span class="_ _38"> </span><span class="fc6">=<span class="_ _38"> </span></span>P.Surname</span></div><div class="t m11 x6c h79 y1a1 ff5b fs59 fc5 sc0 ls0 ws0">AND<span class="_ _38"> </span><span class="fc2">P1.BSN<span class="_ _38"> </span><span class="fc6"><<span class="_ _38"> </span>><span class="_ _38"> </span></span>P.BSN)</span></div><div class="t m11 x6d h7a y1a2 ff5c fs5a fc1 sc0 ls3d ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _4c"> </span>46<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-4" class="step pf w0 h0" data-x="11500" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>How could you rewrite the query from the previous exercise without nested queries?</h4>
<h4>Find the names of customers who live in the same city as the top employee (The one not managed by anyone). <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>How could you rewrite the query from the previous exercise without nested queries?</h4>
<h4>Find the names of customers who live in the same city as the top employee (The one not managed by anyone). <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT customer.firstname, customer.lastname
FROM customer JOIN employee
ON customer.City = employee.City
WHERE employee.ReportsTo IS NULL</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf18" class="step pf w0 h0" data-x="12000" data-y="0" data-scale="0.4" data-page-no="18"><div class="pc pc18 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg18.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Limitations</div><div class="t m0 x6 h8 y1a3 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 y1a4 ff2 fs0 fc2 sc0 ls0 ws0">The quer<span class="_ _9"></span>y is incorr<span class="_ _0"></span>ect because variable <span class="ff5 ls12">D1</span> is not visible in </div><div class="t m0 x9 h2 y1a5 ff2 fs0 fc2 sc0 ls0 ws0">the second nested quer<span class="_ _9"></span>y </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">24</div><div class="c x2c y1a6 w1c h46"><div class="t m12 x53 h7b y1a7 ff5d fs5b fc4 sc0 ls0 ws0">Incorrect<span class="_ _2d"> </span>Example</div><div class="t m12 xe h7c y1a8 ff5e fs5c fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc6">*</span></div><div class="t m12 xe h7c y1a9 ff5e fs5c fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m12 xe h7c y1aa ff5e fs5c fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Dept<span class="_ _2a"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(</span>SELECT<span class="_ _2a"> </span><span class="fc2">DeptName</span></div><div class="t m12 x6e h7c y1ab ff5e fs5c fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Department<span class="_ _2a"> </span>D1</span></div><div class="t m12 x6e h7c y1ac ff5e fs5c fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">DeptName<span class="_ _2a"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"Production"</span></span>)<span class="_ _2a"> </span></span>OR</div><div class="t m12 x6f h7c y1ad ff5e fs5c fc2 sc0 ls0 ws0">Dept<span class="_ _18"> </span><span class="fc5">IN<span class="_ _2a"> </span></span>(<span class="fc5">SELECT<span class="_ _18"> </span></span>DeptName</div><div class="t m12 x6e h7c y1ae ff5e fs5c fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Department<span class="_ _2a"> </span>D2</span></div><div class="t m12 x6e h7c y1af ff5e fs5c fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">D2.City<span class="_ _2a"> </span><span class="fc6">=<span class="_ _18"> </span></span>D1.City)</span></div><div class="t m12 x38 h7d y1b0 ff5f fs5d fc2 sc0 ls3e ws0">The<span class="_ _e"> </span>query<span class="_ _f"> </span>is<span class="_ _f"> </span>inco<span class="_ _0"></span>rrect<span class="_ _e"> </span>b<span class="_ _d"></span>ecause<span class="_ _e"> </span>va<span class="_ _0"></span>riable<span class="_ _e"> </span><span class="ff60 ls0">D1<span class="_ _f"> </span><span class="ff5f">is<span class="_ _f"> </span>not<span class="_ _f"> </span>visibl e<span class="_ _f"> </span>in<span class="_ _f"> </span>the</span></span></div><div class="t m12 x38 h7d y1b1 ff5f fs5d fc2 sc0 ls0 ws0">second<span class="_ _f"> </span>nested<span class="_ _f"> </span>query</div><div class="t m12 x55 h7e y1b2 ff61 fs5e fc1 sc0 ls3f ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _4d"> </span>47<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div><div class="t m0 x70 h8 y1b3 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x5f h2 y1b4 ff2 fs0 fc2 sc0 ls0 ws0">A quer<span class="_ _9"></span>y cannot r<span class="_ _0"></span>efer to attributes in a subquer<span class="_ _9"></span>y<span class="_ _6"></span>, or in a </div><div class="t m0 x5f h2 y1b5 ff2 fs0 fc2 sc0 ls0 ws0">quer<span class="_ _9"></span>y at the same level of nesting </div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf19" class="step pf w0 h0" data-x="12500" data-y="0" data-scale="0.4" data-page-no="19"><div class="pc pc19 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg19.png"/><div class="t m0 x5 h7f y1b6 ff3 fs5f fc2 sc0 ls0 ws0">Example of <span class="ff5 ls40">NOT EXISTS</span> operator</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">25</div><div class="c x4a y1b7 w1d h2f"><div class="t m0 x4b h1 y1b8 ff2 fs0 fc2 sc0 ls0 ws0">Find the name of the suppliers that DO NOT supply P2 <span class="ff1 ls41">or</span></div></div><div class="c xa y1b9 w1 h9"><div class="t m0 x71 ha y1ba ff2 fs6 fc2 sc0 ls0 ws0">Find the name of the suppliers for whom it does not exist at least one </div><div class="t m0 x33 ha y1bb ff2 fs6 fc2 sc0 ls0 ws0">supply of P2</div></div><div class="c x1b y36 w1a h80"><div class="t m13 x47 h81 y1bc ff62 fs60 fc4 sc0 ls0 ws0">Example<span class="_ _29"> </span><span class="ff63">of<span class="_ _4f"> </span><span class="ff64 ls42">NOT<span class="_ _3e"> </span>EXISTS<span class="_ _29"> </span></span>op<span class="_ _3f"></span>erato<span class="_ _3"></span>r</span></div><div class="t m13 x72 h82 y1bd ff65 fs61 fc2 sc0 ls0 ws0">“Find<span class="_ _f"> </span>the<span class="_ _15"> </span>name<span class="_ _f"> </span>of<span class="_ _f"> </span>the<span class="_ _15"> </span>suppliers<span class="_ _15"> </span>that<span class="_ _f"> </span><span class="ff63 ls43">DO<span class="_ _38"> </span>NOT<span class="_ _f"> </span></span>supply<span class="_ _15"> </span>P2”</div><div class="t m13 x72 h82 y1be ff65 fs61 fc2 sc0 ls0 ws0">Also:<span class="_ _48"> </span>“Fin d<span class="_ _15"> </span>the<span class="_ _f"> </span>name<span class="_ _15"> </span>of<span class="_ _f"> </span>the<span class="_ _f"> </span>su p pl i e rs<span class="_ _15"> </span>fo<span class="_ _5"></span>r<span class="_ _15"> </span>whom<span class="_ _f"> </span>it<span class="_ _f"> </span>do<span class="_ _d"></span>es<span class="_ _f"> </span>not<span class="_ _15"> </span>exist</div><div class="t m13 x72 h82 y1bf ff65 fs61 fc2 sc0 ls0 ws0">at<span class="_ _f"> </span>least<span class="_ _15"> </span>one<span class="_ _f"> </span>supply<span class="_ _f"> </span>of<span class="_ _15"> </span>P2”</div><div class="t m13 x3f h83 y1c0 ff66 fs62 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">NameS</span></div><div class="t m13 x3f h83 y1c1 ff66 fs62 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t m13 x3f h83 y1c2 ff66 fs62 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span>NOT<span class="_ _18"> </span>EXISTS<span class="_ _18"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _18"> </span><span class="fc6">*</span></div><div class="t m13 x73 h83 y1c3 ff66 fs62 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t m13 x73 h83 y1c4 ff66 fs62 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeP<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"P2"<span class="_ _18"> </span></span></span></span>AND</div><div class="t m13 x74 h83 y1c5 ff66 fs62 fc2 sc0 ls0 ws0">Supplier.CodeS<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span></span>Supply.CodeS)</div><div class="t m13 x1 h84 y1c6 ff67 fs63 fc1 sc0 ls44 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _50"> </span>49<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-5" class="step pf w0 h0" data-x="13000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the name of songs that have never been sold to USA customers. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.5 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the name of songs that have never been sold to USA customers. </h4>
</asq-stem>
<code></code>
<asq-solution>SELECT DISTINCT T.Name
FROM Track AS T
WHERE NOT EXISTS (
SELECT InvoiceLine.TrackId
FROM Invoice JOIN InvoiceLine
ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN Customer
ON Invoice.CustomerId = Customer.CustomerId
WHERE Customer.Country = "USA"
AND InvoiceLine.TrackId = T.TrackId
)</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf1b" class="step pf w0 h0" data-x="13500" data-y="0" data-scale="0.4" data-page-no="1b"><div class="pc pc1b w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1b.png"/><div class="t m0 x5 h7f y1b6 ff3 fs5f fc2 sc0 ls0 ws0">Example of <span class="ff5 ls40">NOT EXISTS</span> operator</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">27</div><div class="c x4a y1d3 w14 h2f"><div class="t m0 x77 h2 y1d4 ff2 fs0 fc2 sc0 ls0 ws0">Find all the persons who do not have homonyms </div></div><div class="c x5e y1d5 w17 h87"><div class="t m14 x47 h88 y1d6 ff68 fs65 fc4 sc0 ls0 ws0">Another<span class="_ _2d"> </span>Correct<span class="_ _3c"> </span>Example</div><div class="t m14 x15 h89 y1d7 ff69 fs66 fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>all<span class="_ _f"> </span>the<span class="_ _f"> </span>p<span class="_ _d"></span>ersons<span class="_ _f"> </span>wh o<span class="_ _f"> </span>do<span class="_ _15"> </span>not<span class="_ _f"> </span>have<span class="_ _f"> </span>homonyms</div><div class="t m14 x3f h8a y1d8 ff6a fs67 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc6">*</span></div><div class="t m14 x3f h8a y1d9 ff6a fs67 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Person<span class="_ _2a"> </span>P</span></div><div class="t m14 x3f h8a y1da ff6a fs67 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span>NOT<span class="_ _2a"> </span>EXISTS<span class="_ _18"> </span><span class="fc2">(</span>SELECT<span class="_ _18"> </span><span class="fc6">*</span></div><div class="t m14 x78 h8a y1db ff6a fs67 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Person<span class="_ _2a"> </span>P1</span></div><div class="t m14 x78 h8a y1dc ff6a fs67 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">P1.FirstName<span class="_ _2a"> </span><span class="fc6">=<span class="_ _18"> </span></span>P.FirstName</span></div><div class="t m14 x79 h8a y1dd ff6a fs67 fc5 sc0 ls0 ws0">AND<span class="_ _18"> </span><span class="fc2">P1.Surname<span class="_ _2a"> </span><span class="fc6">=<span class="_ _18"> </span></span>P.Surname</span></div><div class="t m14 x79 h8a y1de ff6a fs67 fc5 sc0 ls0 ws0">AND<span class="_ _18"> </span><span class="fc2">P1.BSN<span class="_ _2a"> </span><span class="fc6"><<span class="_ _18"> </span>><span class="_ _18"> </span></span>P.BSN)</span></div><div class="t m14 x56 h8b y1df ff6b fs68 fc1 sc0 ls45 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _51"> </span>48<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-new1" class="step" data-x="14000" data-y="0" data-scale="0.4" data-timer="30">
<asq-exercise style="height: 420px; padding: 20px 20px; background: rgba(255, 255, 255, 0.7); margin-top: 40px;">
<asq-stem class="small"><h4><b>Which operator tests column for the absence of data?</b></h4>
</asq-stem>
<asq-multi-choice-q>
<asq-stem class="hidden"><h4>What operator tests column for the absence of data?</h4>
</asq-stem>
<asq-option class="smaller" style="display: block;" name="a">EXISTS operator</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="b">NOT operator</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="c" correct>IS NULL operator</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="d">None of these</asq-option>
</asq-multi-choice-q>
</asq-exercise>
<div class="flickr-credit">flickr@nasacommons</div>
</div>
<div id="pf1c" class="step pf w0 h0" data-x="14500" data-y="0" data-scale="0.4" data-page-no="1c"><div class="pc pc1c w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1c.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">T<span class="_ _52"></span>uple Constructor</div><div class="t m0 x12 h8 y1e0 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x7a h2 y1e1 ff2 fs0 fc2 sc0 ls0 ws0">The comparison with the nested quer<span class="_ _9"></span>y may involve mor<span class="_ _0"></span>e </div><div class="t m0 x7a h2 y1e2 ff2 fs0 fc2 sc0 ls0 ws0">than one attributes </div><div class="t m0 x12 h8 y1e3 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x7a h2 y1e4 ff2 fs0 fc2 sc0 ls0 ws0">The attributes must be enclosed within a pair of curved </div><div class="t m0 x7a h2 y1e5 ff2 fs0 fc2 sc0 ls0 ws0">brackets (tuple constructor) </div><div class="t m0 x12 h8 y1e6 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x7a h2 y1e7 ff2 fs0 fc2 sc0 ls0 ws0">The quer<span class="_ _9"></span>y in the pr<span class="_ _0"></span>evious slide can be expr<span class="_ _0"></span>essed as: </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">28</div><div class="c x71 y1e8 w1f h8c"><div class="t m15 x7b h8d y1e9 ff6c fs69 fc4 sc0 ls0 ws0">T<span class="_ _53"></span>uple<span class="_ _30"> </span>constructor</div><div class="t m15 x15 h8e y1ea ff6d fs6a fc2 sc0 ls0 ws0">The<span class="_ _15"> </span>compa<span class="_ _0"></span>rison<span class="_ _15"> </span>with<span class="_ _15"> </span>the<span class="_ _15"> </span>n e s ted<span class="_ _25"> </span>query<span class="_ _15"> </span>ma<span class="_ _0"></span>y<span class="_ _15"> </span>involve<span class="_ _15"> </span>mo<span class="_ _5"></span>re<span class="_ _25"> </span>than</div><div class="t m15 x15 h8e y1eb ff6d fs6a fc2 sc0 ls0 ws0">one<span class="_ _15"> </span>attribute</div><div class="t m15 x15 h8e y1ec ff6d fs6a fc2 sc0 ls0 ws0">The<span class="_ _15"> </span>attribute s<span class="_ _25"> </span>must<span class="_ _15"> </span>b<span class="_ _d"></span>e<span class="_ _15"> </span>enclos ed<span class="_ _25"> </span>within<span class="_ _15"> </span>a<span class="_ _25"> </span>pair<span class="_ _15"> </span>of<span class="_ _25"> </span>curved<span class="_ _15"> </span>b<span class="_ _0"></span>rack<span class="_ _5"></span>ets</div><div class="t m15 x15 h8e y1ed ff6d fs6a fc2 sc0 ls0 ws0">(tuple<span class="_ _15"> </span>constru c to<span class="_ _0"></span>r)</div><div class="t m15 x15 h8e y1ee ff6d fs6a fc2 sc0 ls0 ws0">The<span class="_ _15"> </span>query<span class="_ _25"> </span>in<span class="_ _15"> </span>slide<span class="_ _25"> </span>48<span class="_ _15"> </span>can<span class="_ _15"> </span>b<span class="_ _d"></span>e<span class="_ _15"> </span>exp<span class="_ _0"></span>ressed<span class="_ _15"> </span>as:</div><div class="t m15 x61 h8f y1ef ff6e fs6b fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc6">*</span></div><div class="t m15 x61 h8f y1f0 ff6e fs6b fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Person<span class="_ _48"> </span>P</span></div><div class="t m15 x61 h8f y1f1 ff6e fs6b fc5 sc0 ls0 ws0">WHERE<span class="_ _48"> </span><span class="fc2">(FirstName,Surname)<span class="_ _48"> </span></span>NOT<span class="_ _26"> </span>IN<span class="_ _48"> </span><span class="fc2">(<span class="_ _48"> </span></span>SELECT<span class="_ _26"> </span><span class="fc2">FirstName,<span class="_ _48"> </span>Surname</span></div><div class="t m15 x7c h8f y1f2 ff6e fs6b fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Person<span class="_ _48"> </span>P1</span></div><div class="t m15 x7c h8f y1f3 ff6e fs6b fc5 sc0 ls0 ws0">WHERE<span class="_ _48"> </span><span class="fc2">P1.BSN<span class="_ _48"> </span><span class="fc6"><<span class="_ _26"> </span>><span class="_ _48"> </span></span>P.BSN)</span></div><div class="t m15 x7d h90 y1f4 ff6f fs6c fc1 sc0 ls46 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _54"> </span>50<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf1d" class="step pf w0 h0" data-x="15000" data-y="0" data-scale="0.4" data-page-no="1d"><div class="pc pc1d w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1d.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">ANY Operator /1</div><div class="t m0 x7e h8 y1f5 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x10 h2 y1f6 ff2 fs0 fc2 sc0 ls0 ws0">But also</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">29</div><div class="c x4a y1f7 w14 h2f"><div class="t m0 x15 h2 y1f8 ff2 fs0 fc2 sc0 ls0 ws0">Find the employees who work in depar<span class="_ _9"></span>tments in London </div></div><div class="c x20 y1f9 w12 h91"><div class="t m16 x7f h92 y1fa ff70 fs6d fc4 sc0 ls0 ws0">Example<span class="_ _2d"> </span>/1</div><div class="t m16 x38 h93 y1fb ff71 fs6e fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _e"> </span>emp l o<span class="_ _0"></span>y<span class="_ _5"></span>ees<span class="_ _f"> </span>who<span class="_ _e"> </span>w<span class="_ _0"></span>o<span class="_ _5"></span>rk<span class="_ _f"> </span>in<span class="_ _f"> </span>depa<span class="_ _5"></span>rtments<span class="_ _f"> </span>in<span class="_ _f"> </span>London</div><div class="t m16 x27 h94 y1fc ff72 fs6f fc5 sc0 ls0 ws0">SELECT<span class="_ _2a"> </span><span class="fc2">FirstName,<span class="_ _18"> </span>Surname</span></div><div class="t m16 x27 h94 y1fd ff72 fs6f fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Employee</span></div><div class="t m16 x27 h94 y1fe ff72 fs6f fc5 sc0 ls0 ws0">WHERE<span class="_ _2a"> </span><span class="fc2">Dept<span class="_ _18"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc8">ANY<span class="_ _18"> </span></span></span>(<span class="_ _2a"> </span></span>SELECT<span class="_ _18"> </span><span class="fc2">DeptName</span></div><div class="t m16 x80 h94 y1ff ff72 fs6f fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Department</span></div><div class="t m16 x80 h94 y200 ff72 fs6f fc5 sc0 ls0 ws0">WHERE<span class="_ _2a"> </span><span class="fc2">City<span class="_ _18"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"London"</span></span>)</span></div><div class="t m16 x38 h93 y201 ff71 fs6e fc2 sc0 ls47 ws0">But<span class="_ _e"> </span>also</div><div class="t m16 x27 h94 y202 ff72 fs6f fc5 sc0 ls0 ws0">SELECT<span class="_ _2a"> </span><span class="fc2">FirstName,<span class="_ _18"> </span>Surname</span></div><div class="t m16 x27 h94 y203 ff72 fs6f fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Employee,<span class="_ _18"> </span>Department<span class="_ _2a"> </span>D</span></div><div class="t m16 x27 h94 y204 ff72 fs6f fc5 sc0 ls0 ws0">WHERE<span class="_ _2a"> </span><span class="fc2">Dept<span class="_ _18"> </span><span class="fc6">=<span class="_ _2a"> </span></span>DeptName<span class="_ _18"> </span></span>AND<span class="_ _2a"> </span><span class="fc2">D.City<span class="_ _18"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"London"</span></span></span></div><div class="t m16 x81 h95 y205 ff73 fs70 fc1 sc0 ls48 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _2e"> </span>52<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div><div class="c xf y206 w1b h96"><div class="t m17 x47 h97 y207 ff74 fs71 fc4 sc0 ls0 ws0">Example<span class="_ _29"> </span>/1</div><div class="t m17 x13 h98 y208 ff75 fs72 fc2 sc0 ls0 ws0">Find<span class="_ _e"> </span>the<span class="_ _e"> </span>emplo<span class="_ _5"></span>y<span class="_ _0"></span>ees<span class="_ _e"> </span>who<span class="_ _e"> </span>w<span class="_ _5"></span>o<span class="_ _5"></span>rk<span class="_ _e"> </span>i n<span class="_ _e"> </span>depa<span class="_ _0"></span>rtments<span class="_ _e"> </span>in<span class="_ _e"> </span>London</div><div class="t m17 x23 h99 y209 ff76 fs73 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">FirstName,<span class="_ _2a"> </span>Surname</span></div><div class="t m17 x23 h99 y20a ff76 fs73 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Employee</span></div><div class="t m17 x23 h99 y20b ff76 fs73 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Dept<span class="_ _2a"> </span><span class="fc6">=<span class="_ _1d"> </span><span class="fc8">ANY<span class="_ _2a"> </span></span></span>(<span class="_ _1d"> </span></span>SELECT<span class="_ _2a"> </span><span class="fc2">DeptName</span></div><div class="t m17 x82 h99 y20c ff76 fs73 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Department</span></div><div class="t m17 x82 h99 y20d ff76 fs73 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">City<span class="_ _2a"> </span><span class="fc6">=<span class="_ _1d"> </span><span class="fc7">"London"</span></span>)</span></div><div class="t m17 x13 h98 y20e ff75 fs72 fc2 sc0 ls49 ws0">But<span class="_ _16"> </span>also</div><div class="t m17 x23 h99 y20f ff76 fs73 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">FirstName,<span class="_ _2a"> </span>Surname</span></div><div class="t m17 x23 h99 y210 ff76 fs73 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Employee,<span class="_ _2a"> </span>Department<span class="_ _1d"> </span>D</span></div><div class="t m17 x23 h99 y211 ff76 fs73 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Dept<span class="_ _2a"> </span><span class="fc6">=<span class="_ _1d"> </span></span>DeptName<span class="_ _2a"> </span></span>AND<span class="_ _1d"> </span><span class="fc2">D.City<span class="_ _2a"> </span><span class="fc6">=<span class="_ _1d"> </span><span class="fc7">"London"</span></span></span></div><div class="t m17 x83 h9a y212 ff77 fs74 fc1 sc0 ls4a ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _55"> </span>52<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf1e" class="step pf w0 h0" data-x="15500" data-y="0" data-scale="0.4" data-page-no="1e"><div class="pc pc1e w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1e.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">ANY Operator /2</div><div class="t m0 x7e h8 y1f5 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x10 h2 y1f6 ff2 fs0 fc2 sc0 ls0 ws0">But also</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">30</div><div class="c xa y213 w1 h9"><div class="t m0 x1f ha y214 ff2 fs6 fc2 sc0 ls0 ws0">Find the employees of the Planning depar<span class="_ _9"></span>tment, having the same first </div><div class="t m0 x84 ha y215 ff2 fs6 fc2 sc0 ls0 ws0">name as a member of the Pr<span class="_ _0"></span>oduction depar<span class="_ _9"></span>tment </div></div><div class="c x46 y216 w16 h9b"><div class="t m18 x7f h9c y217 ff78 fs75 fc4 sc0 ls0 ws0">Example<span class="_ _30"> </span>/2</div><div class="t m18 x38 h9d y218 ff79 fs76 fc2 sc0 ls0 ws0">Find<span class="_ _e"> </span>the<span class="_ _e"> </span>emplo<span class="_ _0"></span>y<span class="_ _5"></span>ees<span class="_ _e"> </span>of<span class="_ _e"> </span>the<span class="_ _e"> </span>Planning<span class="_ _e"> </span>depa<span class="_ _0"></span>rtment,<span class="_ _e"> </span>having<span class="_ _e"> </span>the<span class="_ _e"> </span>same</div><div class="t m18 x38 h9d y219 ff79 fs76 fc2 sc0 ls0 ws0">first<span class="_ _e"> </span>name<span class="_ _e"> </span>as<span class="_ _e"> </span>a<span class="_ _e"> </span>memb<span class="_ _d"></span>er<span class="_ _e"> </span>of<span class="_ _e"> </span>the<span class="_ _e"> </span>Pro<span class="_ _d"></span>duction<span class="_ _e"> </span>depa<span class="_ _5"></span>r tme nt</div><div class="t m18 x29 h9e y21a ff7a fs77 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">FirstName,<span class="_ _2a"> </span>Surname</span></div><div class="t m18 x29 h9e y21b ff7a fs77 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Employee</span></div><div class="t m18 x29 h9e y21c ff7a fs77 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Dept<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"Planning"</span></span></span></div><div class="t m18 x6f h9e y21d ff7a fs77 fc5 sc0 ls0 ws0">AND<span class="_ _1d"> </span><span class="fc2">FirstName<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc8">ANY<span class="_ _1d"> </span></span></span>(<span class="_ _2a"> </span></span>SELECT<span class="_ _2a"> </span><span class="fc2">FirstName</span></div><div class="t m18 x85 h9e y21e ff7a fs77 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Employee</span></div><div class="t m18 x85 h9e y21f ff7a fs77 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">Dept<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"Production"</span></span>)</span></div><div class="t m18 x38 h9d y220 ff79 fs76 fc2 sc0 ls4b ws0">But<span class="_ _e"> </span>also</div><div class="t m18 x29 h9e y221 ff7a fs77 fc5 sc0 ls0 ws0">SELECT<span class="_ _1d"> </span><span class="fc2">E1.FirstName,<span class="_ _2a"> </span>E1.Surname</span></div><div class="t m18 x29 h9e y222 ff7a fs77 fc5 sc0 ls0 ws0">FROM<span class="_ _1d"> </span><span class="fc2">Employee<span class="_ _2a"> </span>E1,<span class="_ _2a"> </span>Employee<span class="_ _1d"> </span>E2</span></div><div class="t m18 x29 h9e y223 ff7a fs77 fc5 sc0 ls0 ws0">WHERE<span class="_ _1d"> </span><span class="fc2">E1.FirstName<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span></span>E2.FirstName<span class="_ _1d"> </span></span>AND<span class="_ _2a"> </span><span class="fc2">E2.Dept<span class="fc6">=<span class="fc7">"Production"</span></span></span></div><div class="t m18 x6f h9e y224 ff7a fs77 fc5 sc0 ls0 ws0">AND<span class="_ _1d"> </span><span class="fc2">E1.Dept<span class="_ _2a"> </span><span class="fc6">=<span class="_ _2a"> </span><span class="fc7">"Planning"</span></span></span></div><div class="t m18 x86 h9f y225 ff7b fs78 fc1 sc0 ls4c ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _56"> </span>53<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="c x2c y206 w1c ha0"><div class="t m19 x53 ha1 y226 ff7c fs79 fc4 sc0 ls0 ws0">Example<span class="_ _29"> </span>/2</div><div class="t m19 x12 ha2 y227 ff7d fs7a fc2 sc0 ls0 ws0">Find<span class="_ _16"> </span>the<span class="_ _16"> </span>emplo<span class="_ _5"></span>y<span class="_ _0"></span>ees<span class="_ _16"> </span>of<span class="_ _16"> </span>the<span class="_ _16"> </span>Planning<span class="_ _16"> </span>depa<span class="_ _5"></span>rtm en t,<span class="_ _16"> </span>havin g<span class="_ _16"> </span>the<span class="_ _16"> </span>same</div><div class="t m19 x12 ha2 y228 ff7d fs7a fc2 sc0 ls0 ws0">first<span class="_ _16"> </span>name<span class="_ _16"> </span>as<span class="_ _16"> </span>a<span class="_ _16"> </span>memb<span class="_ _9"></span>er<span class="_ _16"> </span>of<span class="_ _16"> </span>the<span class="_ _16"> </span>Pro<span class="_ _d"></span>duction<span class="_ _16"> </span>depa<span class="_ _5"></span>rtm en t</div><div class="t m19 xe ha3 y229 ff7e fs7b fc5 sc0 ls0 ws0">SELECT<span class="_ _57"> </span><span class="fc2">FirstName,<span class="_ _57"> </span>Surname</span></div><div class="t m19 xe ha3 y22a ff7e fs7b fc5 sc0 ls0 ws0">FROM<span class="_ _57"> </span><span class="fc2">Employee</span></div><div class="t m19 xe ha3 y22b ff7e fs7b fc5 sc0 ls0 ws0">WHERE<span class="_ _57"> </span><span class="fc2">Dept<span class="_ _57"> </span><span class="fc6">=<span class="_ _57"> </span><span class="fc7">"Planning"</span></span></span></div><div class="t m19 x16 ha3 y22c ff7e fs7b fc5 sc0 ls0 ws0">AND<span class="_ _57"> </span><span class="fc2">FirstName<span class="_ _57"> </span><span class="fc6">=<span class="_ _57"> </span><span class="fc8">ANY<span class="_ _57"> </span></span></span>(<span class="_ _57"> </span></span>SELECT<span class="_ _57"> </span><span class="fc2">FirstName</span></div><div class="t m19 x5d ha3 y22d ff7e fs7b fc5 sc0 ls0 ws0">FROM<span class="_ _57"> </span><span class="fc2">Employee</span></div><div class="t m19 x5d ha3 y22e ff7e fs7b fc5 sc0 ls0 ws0">WHERE<span class="_ _57"> </span><span class="fc2">Dept<span class="_ _57"> </span><span class="fc6">=<span class="_ _57"> </span><span class="fc7">"Production"</span></span>)</span></div><div class="t m19 x12 ha2 y22f ff7d fs7a fc2 sc0 ls4d ws0">But<span class="_ _16"> </span>also</div><div class="t m19 xe ha3 y230 ff7e fs7b fc5 sc0 ls0 ws0">SELECT<span class="_ _57"> </span><span class="fc2">E1.FirstName,<span class="_ _57"> </span>E1.Surname</span></div><div class="t m19 xe ha3 y231 ff7e fs7b fc5 sc0 ls0 ws0">FROM<span class="_ _57"> </span><span class="fc2">Employee<span class="_ _57"> </span>E1,<span class="_ _57"> </span>Employee<span class="_ _57"> </span>E2</span></div><div class="t m19 xe ha3 y232 ff7e fs7b fc5 sc0 ls0 ws0">WHERE<span class="_ _57"> </span><span class="fc2">E1.FirstName<span class="_ _57"> </span><span class="fc6">=<span class="_ _57"> </span></span>E2.FirstName<span class="_ _57"> </span></span>AND<span class="_ _57"> </span><span class="fc2">E2.Dept<span class="fc6">=<span class="fc7">"Production"</span></span></span></div><div class="t m19 x16 ha3 y233 ff7e fs7b fc5 sc0 ls0 ws0">AND<span class="_ _57"> </span><span class="fc2">E1.Dept<span class="_ _57"> </span><span class="fc6">=<span class="_ _57"> </span><span class="fc7">"Planning"</span></span></span></div><div class="t m19 x74 ha4 y234 ff7f fs7c fc1 sc0 ls4e ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _2b"> </span>Queries<span class="_ _58"> </span>53<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf1f" class="step pf w0 h0" data-x="16000" data-y="0" data-scale="0.4" data-page-no="1f"><div class="pc pc1f w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg1f.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example <span class="ff5 ls21">MIN</span> and <span class="ff5 ls21">MAX</span></div><div class="t m0 x12 h8 y235 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x7a h2 y236 ff2 fs0 fc2 sc0 ls0 ws0">Queries using the aggr<span class="_ _0"></span>egate operators max and min can be </div><div class="t m0 x7a h2 y237 ff2 fs0 fc2 sc0 ls0 ws0">expr<span class="_ _0"></span>essed with nested queries </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">31</div><div class="c x1b yf w18 ha5"><div class="t m1a x53 ha6 y238 ff80 fs7d fc4 sc0 ls0 ws0">Example:<span class="_ _59"> </span><span class="ff81 ls4f">Min<span class="_ _2d"> </span></span>and<span class="_ _2d"> </span><span class="ff81 ls4f">Max</span></div><div class="t m1a x38 ha7 y239 ff82 fs7e fc2 sc0 ls0 ws0">Queries<span class="_ _f"> </span>using<span class="_ _15"> </span>the<span class="_ _f"> </span>aggregate<span class="_ _f"> </span>op<span class="_ _d"></span>erato<span class="_ _0"></span>rs<span class="_ _e"> </span>ma x<span class="_ _15"> </span>and<span class="_ _f"> </span>min<span class="_ _f"> </span>can<span class="_ _15"> </span>b<span class="_ _d"></span>e</div><div class="t m1a x38 ha7 y23a ff82 fs7e fc2 sc0 ls50 ws0">exp<span class="_ _5"></span>ressed<span class="_ _f"> </span>with<span class="_ _f"> </span>nested<span class="_ _15"> </span>queries</div><div class="t m1a xe ha8 y23b ff83 fs7f fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Dept</span></div><div class="t m1a xe ha8 y23c ff83 fs7f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m1a xe ha8 y23d ff83 fs7f fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Salary<span class="_ _18"> </span><span class="fc6">>=<span class="_ _18"> </span></span></span>ALL<span class="_ _2a"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _18"> </span><span class="fc2">Salary</span></div><div class="t m1a x48 ha8 y23e ff83 fs7f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee)</span></div><div class="t m1a x38 ha7 y23f ff82 fs7e fc2 sc0 ls51 ws0">But<span class="_ _f"> </span>also</div><div class="t m1a xe ha8 y240 ff83 fs7f fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Dept</span></div><div class="t m1a xe ha8 y241 ff83 fs7f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m1a xe ha8 y242 ff83 fs7f fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Salary<span class="_ _18"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _2a"> </span></span>SELECT<span class="_ _18"> </span><span class="fc8">max<span class="fc2">(Salary)</span></span></div><div class="t m1a x11 ha8 y243 ff83 fs7f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee)</span></div><div class="t m1a x5d ha9 y244 ff84 fs80 fc1 sc0 ls52 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _43"> </span>55<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div><div class="t m0 x12 h8 y245 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x7a h2 y246 ff2 fs0 fc2 sc0 ls0 ws0">But also</div><div class="c x6 y247 w20 haa"><div class="t m1b x53 hab y248 ff85 fs81 fc4 sc0 ls0 ws0">Example:<span class="_ _59"> </span><span class="ff86 ls53">Min<span class="_ _29"> </span></span>and<span class="_ _2d"> </span><span class="ff86 ls53">Max</span></div><div class="t m1b x38 hac y249 ff87 fs82 fc2 sc0 ls0 ws0">Queries<span class="_ _f"> </span>using<span class="_ _f"> </span>the<span class="_ _f"> </span>aggregate<span class="_ _f"> </span>op<span class="_ _d"></span>erato<span class="_ _0"></span>rs<span class="_ _e"> </span>max<span class="_ _f"> </span>and<span class="_ _f"> </span>mi n<span class="_ _15"> </span>can<span class="_ _f"> </span>b<span class="_ _d"></span>e</div><div class="t m1b x38 hac y24a ff87 fs82 fc2 sc0 ls54 ws0">exp<span class="_ _5"></span>ressed<span class="_ _f"> </span>with<span class="_ _f"> </span>nested<span class="_ _f"> </span>queries</div><div class="t m1b x27 had y24b ff88 fs83 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Dept</span></div><div class="t m1b x27 had y24c ff88 fs83 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m1b x27 had y24d ff88 fs83 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Salary<span class="_ _2a"> </span><span class="fc6">>=<span class="_ _18"> </span></span></span>ALL<span class="_ _18"> </span><span class="fc2">(<span class="_ _2a"> </span></span>SELECT<span class="_ _18"> </span><span class="fc2">Salary</span></div><div class="t m1b x87 had y24e ff88 fs83 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee)</span></div><div class="t m1b x38 hac y24f ff87 fs82 fc2 sc0 ls55 ws0">But<span class="_ _e"> </span>also</div><div class="t m1b x27 had y250 ff88 fs83 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Dept</span></div><div class="t m1b x27 had y251 ff88 fs83 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m1b x27 had y252 ff88 fs83 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Salary<span class="_ _2a"> </span></span>IN<span class="_ _18"> </span><span class="fc2">(<span class="_ _18"> </span></span>SELECT<span class="_ _2a"> </span><span class="fc8">max<span class="fc2">(Salary)</span></span></div><div class="t m1b x88 had y253 ff88 fs83 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee)</span></div><div class="t m1b x55 hae y254 ff89 fs84 fc1 sc0 ls56 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _35"> </span>55<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf20" class="step pf w0 h0" data-x="16500" data-y="0" data-scale="0.4" data-page-no="20"><div class="pc pc20 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg20.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Example of negation with <span class="ff5 ls21">ALL</span></div><div class="t m0 x6 h8 y255 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h2 y256 ff2 fs0 fc2 sc0 ls0 ws0">Alter<span class="_ _9"></span>natively (mor<span class="_ _0"></span>e next) </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">32</div><div class="c x4a y257 w14 h2f"><div class="t m0 x5e h2 y258 ff2 fs0 fc2 sc0 ls0 ws0">Find the depar<span class="_ _9"></span>tments in which ther<span class="_ _0"></span>e is no one named Br<span class="_ _0"></span>own </div></div><div class="c x4a y1e7 w14 haf"><div class="t m1c x7b hb0 y259 ff8a fs85 fc4 sc0 ls0 ws0">Example<span class="_ _3c"> </span>of<span class="_ _3c"> </span>Negation<span class="_ _3c"> </span>with<span class="_ _3c"> </span><span class="ff8b ls57">ANY</span></div><div class="t m1c x1c hb1 y25a ff8c fs86 fc2 sc0 ls0 ws0">Find<span class="_ _17"> </span>the<span class="_ _16"> </span>depa<span class="_ _5"></span>rtments<span class="_ _17"> </span>in<span class="_ _16"> </span>which<span class="_ _17"> </span>there<span class="_ _17"> </span>is<span class="_ _16"> </span>no<span class="_ _17"> </span>one<span class="_ _17"> </span>named<span class="_ _17"> </span>Bro<span class="_ _0"></span>wn</div><div class="t m1c x61 hb2 y25b ff8d fs87 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">DeptName</span></div><div class="t m1c x61 hb2 y25c ff8d fs87 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Department</span></div><div class="t m1c x61 hb2 y25d ff8d fs87 fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">DeptName<span class="_ _5a"> </span><span class="fc6"><<span class="_ _21"> </span>><span class="_ _5a"> </span></span></span>ALL<span class="_ _21"> </span><span class="fc2">(<span class="_ _5a"> </span></span>SELECT<span class="_ _21"> </span><span class="fc2">Dept</span></div><div class="t m1c x89 hb2 y25e ff8d fs87 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Employee</span></div><div class="t m1c x89 hb2 y25f ff8d fs87 fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Surname<span class="_ _5a"> </span><span class="fc6">=<span class="_ _21"> </span><span class="fc7">"Brown"</span></span>)</span></div><div class="t m1c x1c hb1 y260 ff8c fs86 fc2 sc0 ls58 ws0">Alternatively<span class="_ _17"> </span>(mo<span class="_ _5"></span>re<span class="_ _17"> </span>in<span class="_ _16"> </span>few<span class="_ _1c"> </span>slides)</div><div class="t m1c x8a hb2 y261 ff8d fs87 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">DeptName</span></div><div class="t m1c x8a hb2 y262 ff8d fs87 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Department</span></div><div class="t m1c x61 hb2 y263 ff8d fs87 fc2 sc0 ls0 ws0">EXCEPT</div><div class="t m1c x8a hb2 y264 ff8d fs87 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">Dept</span></div><div class="t m1c x8a hb2 y265 ff8d fs87 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Employee</span></div><div class="t m1c x8a hb2 y266 ff8d fs87 fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Surname<span class="_ _5a"> </span><span class="fc6">=<span class="_ _21"> </span><span class="fc7">"Brown"</span></span></span></div><div class="t m1c x8b hb3 y267 ff8e fs88 fc1 sc0 ls59 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _5b"> </span>58<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div><div class="c x20 y268 w21 hb4"><div class="t m1d x8c hb5 y269 ff8f fs89 fc4 sc0 ls0 ws0">Example<span class="_ _5c"> </span>of<span class="_ _5c"> </span>Negation<span class="_ _5c"> </span>with<span class="_ _5c"> </span><span class="ff90 ls5a">ANY</span></div><div class="t m1d x4b hb6 y26a ff91 fs8a fc2 sc0 ls0 ws0">Find<span class="_ _20"> </span>the<span class="_ _20"> </span>depa<span class="_ _0"></span>rtments<span class="_ _20"> </span>in<span class="_ _20"> </span>wh ic h<span class="_ _1f"> </span>there<span class="_ _20"> </span>is<span class="_ _20"> </span>no<span class="_ _20"> </span>one<span class="_ _20"> </span>named<span class="_ _1f"> </span>Bro<span class="_ _0"></span>wn</div><div class="t m1d x5b hb7 y26b ff92 fs8b fc5 sc0 ls0 ws0">SELECT<span class="_ _15"> </span><span class="fc2">DeptName</span></div><div class="t m1d x5b hb7 y26c ff92 fs8b fc5 sc0 ls0 ws0">FROM<span class="_ _15"> </span><span class="fc2">Department</span></div><div class="t m1d x5b hb7 y26d ff92 fs8b fc5 sc0 ls0 ws0">WHERE<span class="_ _15"> </span><span class="fc2">DeptName<span class="_ _25"> </span><span class="fc6"><<span class="_ _25"> </span>><span class="_ _25"> </span></span></span>ALL<span class="_ _25"> </span><span class="fc2">(<span class="_ _15"> </span></span>SELECT<span class="_ _25"> </span><span class="fc2">Dept</span></div><div class="t m1d x8d hb7 y26e ff92 fs8b fc5 sc0 ls0 ws0">FROM<span class="_ _15"> </span><span class="fc2">Employee</span></div><div class="t m1d x8d hb7 y26f ff92 fs8b fc5 sc0 ls0 ws0">WHERE<span class="_ _15"> </span><span class="fc2">Surname<span class="_ _25"> </span><span class="fc6">=<span class="_ _25"> </span><span class="fc7">"Brown"</span></span>)</span></div><div class="t m1d x4b hb6 y270 ff91 fs8a fc2 sc0 ls5b ws0">Alternatively<span class="_ _20"> </span>(mo<span class="_ _5"></span>re<span class="_ _20"> </span>in<span class="_ _20"> </span>few<span class="_ _20"> </span>slides)</div><div class="t m1d x71 hb7 y271 ff92 fs8b fc5 sc0 ls0 ws0">SELECT<span class="_ _15"> </span><span class="fc2">DeptName</span></div><div class="t m1d x71 hb7 y272 ff92 fs8b fc5 sc0 ls0 ws0">FROM<span class="_ _15"> </span><span class="fc2">Department</span></div><div class="t m1d x5b hb7 y273 ff92 fs8b fc2 sc0 ls0 ws0">EXCEPT</div><div class="t m1d x71 hb7 y274 ff92 fs8b fc5 sc0 ls0 ws0">SELECT<span class="_ _15"> </span><span class="fc2">Dept</span></div><div class="t m1d x71 hb7 y275 ff92 fs8b fc5 sc0 ls0 ws0">FROM<span class="_ _15"> </span><span class="fc2">Employee</span></div><div class="t m1d x71 hb7 y276 ff92 fs8b fc5 sc0 ls0 ws0">WHERE<span class="_ _15"> </span><span class="fc2">Surname<span class="_ _25"> </span><span class="fc6">=<span class="_ _25"> </span><span class="fc7">"Brown"</span></span></span></div><div class="t m1d x2b hb8 y277 ff93 fs8c fc1 sc0 ls5c ws0">Advanced<span class="_ _5d"> </span>SQL<span class="_ _5d"> </span>Queries<span class="_ _5e"> </span>58<span class="_ _5d"> </span>/<span class="_ _5d"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf21" class="step pf w0 h0" data-x="17000" data-y="0" data-scale="0.4" data-page-no="21"><div class="pc pc21 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg21.png"/><div class="t m0 x5 hb9 y278 ff3 fs8d fc2 sc0 ls0 ws0">Nested and <span class="_ _5f"></span>Aggr<span class="_ _3"></span>egated Queries</div><div class="t m0 x7e h8 y279 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x10 h2 y27a ff2 fs0 fc2 sc0 ls0 ws0">All the pr<span class="_ _0"></span>oducts that can be supplied ar<span class="_ _0"></span>e in the <span class="ff5 ls12">Product</span> table </div><div class="t m0 x7e h8 y27b ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x10 h2 y27c ff2 fs0 fc2 sc0 ls0 ws0">A supplier supply all the pr<span class="_ _0"></span>oducts if the number of distinct </div><div class="t m0 x10 h2 y27d ff2 fs0 fc2 sc0 ls0 ws0">supplied pr<span class="_ _0"></span>oduct is the same as the number of available </div><div class="t m0 x10 h2 y27e ff2 fs0 fc2 sc0 ls0 ws0">pr<span class="_ _0"></span>oducts </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">33</div><div class="c x4a y27f w14 h2f"><div class="t m0 x72 h2 y280 ff2 fs0 fc2 sc0 ls0 ws0">Find the code of the suppliers that supply ALL pr<span class="_ _0"></span>oducts </div></div><div class="c x1b y281 w18 h1c"><div class="t m1e x7b hba y282 ff94 fs8e fc4 sc0 ls0 ws0">Example</div><div class="t m1e x15 hbb y283 ff95 fs8f fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _f"> </span>co<span class="_ _d"></span>de<span class="_ _f"> </span>of<span class="_ _15"> </span>the<span class="_ _f"> </span>suppliers<span class="_ _15"> </span>that<span class="_ _f"> </span>supply<span class="_ _25"> </span><span class="ff96 ls5d">ALL<span class="_ _f"> </span></span><span class="ls5e">pr<span class="_ _d"></span>o<span class="_ _3f"></span>d<span class="_ _d"></span>u<span class="_ _d"></span>c<span class="_ _d"></span>t<span class="_ _9"></span>s</span></div><div class="t m1e x61 hbc y284 ff97 fs90 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t m1e x61 hbc y285 ff97 fs90 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t m1e x61 hbc y286 ff97 fs90 fc5 sc0 ls0 ws0">GROUP<span class="_ _18"> </span>BY<span class="_ _18"> </span><span class="fc2">CodeS</span></div><div class="t m1e x61 hbc y287 ff97 fs90 fc5 sc0 ls0 ws0">HAVING<span class="_ _18"> </span><span class="fc8">COUNT<span class="fc2">(<span class="fc6">*</span>)<span class="_ _18"> </span><span class="fc6">=<span class="_ _18"> </span></span>(<span class="_ _2a"> </span></span></span>SELECT<span class="_ _18"> </span><span class="fc8">COUNT<span class="fc2">(<span class="fc6">*</span>)</span></span></div><div class="t m1e x8e hbc y288 ff97 fs90 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Product)</span></div><div class="t m1e x15 hbb y289 ff95 fs8f fc2 sc0 ls5f ws0">All<span class="_ _f"> </span>the<span class="_ _f"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts<span class="_ _f"> </span>that<span class="_ _f"> </span>can<span class="_ _f"> </span>b<span class="_ _d"></span>e<span class="_ _f"> </span>supplied<span class="_ _f"> </span>a<span class="_ _5"></span>re<span class="_ _f"> </span>in<span class="_ _15"> </span>the<span class="_ _f"> </span><span class="ff98 ls0">Product<span class="_ _f"> </span></span><span class="ls60">table</span></div><div class="t m1e x15 hbb y28a ff95 fs8f fc2 sc0 ls0 ws0">A<span class="_ _f"> </span>supplier<span class="_ _15"> </span>supply<span class="_ _f"> </span>all<span class="_ _15"> </span>the<span class="_ _f"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts<span class="_ _f"> </span>i f<span class="_ _15"> </span>the<span class="_ _f"> </span>numb<span class="_ _d"></span>er<span class="_ _f"> </span>of<span class="_ _f"> </span>di s ti nc t</div><div class="t m1e x15 hbb y28b ff95 fs8f fc2 sc0 ls0 ws0">supplied<span class="_ _f"> </span>p<span class="_ _0"></span>ro<span class="_ _d"></span>duct<span class="_ _e"> </span>i s<span class="_ _15"> </span>the<span class="_ _f"> </span>same<span class="_ _f"> </span>as<span class="_ _15"> </span>the<span class="_ _f"> </span>numb<span class="_ _d"></span>er<span class="_ _f"> </span>of<span class="_ _f"> </span>ava i l abl e<span class="_ _15"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts</div><div class="t m1e x56 hbd y28c ff99 fs91 fc1 sc0 ls61 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _43"> </span>56<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf21new" class="step pf w0 h0" data-x="17500" data-y="0" data-scale="0.4" data-page-no="21new"><div class="pc pc21 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/new.jpg"/></div></div>
<div id="asq-6" class="step pf w0 h0" data-x="18000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the "TV Shows" tracks that sold more than the average "Drama" track. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.6 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the "TV Shows" tracks that sold more than the average "Drama" track. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT track.TrackId,
SUM(InvoiceLine.UnitPrice * InvoiceLine.Quantity) as Total
FROM track JOIN InvoiceLine
ON InvoiceLine.TrackId = track.TrackId
WHERE track.genreId = 19
GROUP BY track.TrackId
HAVING Total >= (
SELECT avg(InvoiceLine.UnitPrice * InvoiceLine.Quantity)
FROM track JOIN InvoiceLine ON InvoiceLine.TrackId = track.TrackId
WHERE track.genreId = 21)
ORDER BY Total DESC</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf23" class="step pf w0 h0" data-x="18500" data-y="0" data-scale="0.4" data-page-no="23"><div class="pc pc23 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg23.png"/><div class="t m0 x94 he y28 ff3 fs8 fc2 sc0 ls0 ws0">Set Queries</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf24" class="step pf w0 h0" data-x="19000" data-y="0" data-scale="0.4" data-page-no="24"><div class="pc pc24 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg24.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Set Queries</div><div class="t m0 x71 h8 y299 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x95 h2 y29a ff2 fs0 fc2 sc0 ls0 ws0">Union, intersection, and dif<span class="_ _0"></span>fer<span class="_ _0"></span>ence of r<span class="_ _0"></span>elations ar<span class="_ _0"></span>e expr<span class="_ _0"></span>essed by </div><div class="t m0 x95 h2 y29b ff2 fs0 fc2 sc0 ls0 ws0">the following for<span class="_ _9"></span>ms, each involving subqueries: </div><div class="t m0 x6 hc0 y29c ff5 fs93 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 hc1 y29d ff5 fs94 fc2 sc0 ls63 ws0">(subquery) INTERSECT [ALL] (subquery)</div><div class="t m0 x6 hc0 y29e ff5 fs93 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 hc1 y29f ff5 fs94 fc2 sc0 ls63 ws0">(subquery) EXCEPT [ALL] (subquery)</div><div class="t m0 x6 hc0 y2a0 ff5 fs93 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 hc1 y2a1 ff5 fs94 fc2 sc0 ls63 ws0">(subquery) UNION [ALL] (subquery)</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">36</div><div class="c x96 y2a2 w23 hc2"><div class="t m0 xb hc3 y2a3 ff2 fs94 fc1 sc0 ls0 ws0">Can be expr<span class="_ _0"></span>essed </div><div class="t m0 x97 hc3 y2a4 ff2 fs94 fc1 sc0 ls0 ws0">with other operators </div><div class="t m0 x27 hc3 y2a5 ff2 fs94 fc1 sc0 ls0 ws0">(typically sub-queries)</div></div><div class="c x98 y2a6 w23 hc2"><div class="t m0 x1f hc3 y2a7 ff2 fs94 fc1 sc0 ls0 ws0">Enhancement of the </div><div class="t m0 x8a hc3 y2a8 ff2 fs94 fc1 sc0 ls0 ws0">expr<span class="_ _0"></span>essive power</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf25" class="step pf w0 h0" data-x="19500" data-y="0" data-scale="0.4" data-page-no="25"><div class="pc pc25 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg25.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Set Semantic of Set Queries</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">37</div><div class="t m0 x20 h8 y2a9 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h2 y2aa ff2 fs0 fc2 sc0 ls0 ws0">Although the <span class="ff5 ls12">SELECT-FROM-WHERE</span> statement uses bag </div><div class="t m0 x54 h2 y16f ff2 fs0 fc2 sc0 ls0 ws0">semantics, the default for union, intersection, and dif<span class="_ _0"></span>fer<span class="_ _0"></span>ence is </div><div class="t m0 x54 h2 y123 ff2 fs0 fc2 sc0 ls0 ws0">set semantics. </div><div class="t m0 x99 h8 y2ab ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x76 h2 y2ac ff2 fs0 fc2 sc0 ls0 ws0">That is, duplicates ar<span class="_ _0"></span>e eliminated as the operation is applied </div><div class="t m0 x20 h8 y2ad ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x54 h1 y2ae ff2 fs0 fc2 sc0 ls0 ws0">Motivation: <span class="ff1">Efficiency</span></div><div class="t m0 x99 h8 y2af ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x76 h2 y2b0 ff2 fs0 fc2 sc0 ls0 ws0">When <span class="ff6">pr<span class="_ _0"></span>ojecting<span class="ff2"> attributes, it is easier to avoid eliminating </span></span></div><div class="t m0 x76 h2 y2b1 ff2 fs0 fc2 sc0 ls0 ws0">duplicates. Just work tuple-at-a-time. </div><div class="t m0 x99 h8 y2b2 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x76 h2 y2b3 ff2 fs0 fc2 sc0 ls0 ws0">When doing intersection or dif<span class="_ _0"></span>fer<span class="_ _0"></span>ence, it is most ef<span class="_ _0"></span>ficient to </div><div class="t m0 x76 h2 y2b4 ff2 fs0 fc2 sc0 ls0 ws0">sor<span class="_ _9"></span>t the r<span class="_ _0"></span>elations first. At that point you may as well eliminate </div><div class="t m0 x76 h2 y2b5 ff2 fs0 fc2 sc0 ls0 ws0">the duplicates anyway</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf26" class="step pf w0 h0" data-x="20000" data-y="0" data-scale="0.4" data-page-no="26"><div class="pc pc26 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg26.png"/><div class="t m0 x5 hc4 y5 ff5 fs2 fc2 sc0 ls21 ws0">UNION</div><div class="t m0 x4a hc5 y2b6 ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x1c hc6 y2b7 ff2 fs96 fc2 sc0 ls0 ws0">It executes the union of two r<span class="_ _0"></span>elational expr<span class="_ _0"></span>essions </div><div class="t m0 x15 hc5 y2b8 ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9a hc6 y2b9 ff2 fs96 fc2 sc0 ls0 ws0">Expr<span class="_ _0"></span>essions generated by <span class="ff5 ls64">SELECT</span> clauses </div><div class="t m0 x15 hc7 y2ba ff1 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9a hc8 y2bb ff1 fs96 fc2 sc0 ls0 ws0">A<span class="_ _5"></span> and B must have compatible schema </div><div class="t m0 x17 hc5 y2bc ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9b hc6 y2bd ff2 fs96 fc2 sc0 ls0 ws0">select queries must have the same number of output fields, in </div><div class="t m0 x9b hc6 y2b1 ff2 fs96 fc2 sc0 ls0 ws0">the same or<span class="_ _0"></span>der<span class="_ _a"></span>, and with the same or compatible data types </div><div class="t m0 x15 hc5 y2be ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9a hc6 y2bf ff2 fs96 fc2 sc0 ls0 ws0">Duplicate r<span class="_ _0"></span>emoval </div><div class="t m0 x17 hc5 y2c0 ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9b hc6 y2c1 ff5 fs96 fc2 sc0 ls64 ws0">UNION<span class="ff2 ls0"> r<span class="_ _0"></span>emoves duplicates </span></div><div class="t m0 x17 hc5 y2c2 ff2 fs95 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9b hc6 y2c3 ff5 fs96 fc2 sc0 ls64 ws0">UNION ALL<span class="ff2 ls0"> does not r<span class="_ _0"></span>emove duplicates </span></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">38</div><div class="c x36 y123 w24 hc9"><div class="t m1f x53 hca y2c4 ff9a fs97 fc4 sc0 ls65 ws0">UNION</div><div class="t m1f x13 hcb y2c5 ff9b fs98 fc2 sc0 ls0 ws0">A<span class="_ _15"> </span>single<span class="_ _15"> </span><span class="ff9c">SELECT<span class="_ _15"> </span></span>ca nn ot<span class="_ _25"> </span>rep<span class="_ _5"></span>resent<span class="_ _25"> </span>unions<span class="_ _15"> </span>of<span class="_ _15"> </span>values<span class="_ _25"> </span>from<span class="_ _15"> </span>t<span class="_ _5"></span>w<span class="_ _0"></span>o<span class="_ _f"> </span>o<span class="_ _0"></span>r</div><div class="t m1f x13 hcb y2c6 ff9b fs98 fc2 sc0 ls66 ws0">mo<span class="_ _5"></span>re<span class="_ _15"> </span>tables</div><div class="t m1f x27 hcc y2c7 ff9d fs99 fc2 sc0 ls0 ws0">A<span class="_ _48"> </span><span class="fc5">UNION<span class="_ _48"> </span></span>B</div><div class="t m1f x13 hcb y2c8 ff9b fs98 fc2 sc0 ls0 ws0">It<span class="_ _15"> </span>executes<span class="_ _15"> </span>the<span class="_ _25"> </span>union<span class="_ _15"> </span>of<span class="_ _15"> </span>t<span class="_ _5"></span>w<span class="_ _0"></span>o<span class="_ _15"> </span>relational<span class="_ _15"> </span>exp<span class="_ _0"></span>ressions</div><div class="t m1f x1a hcd y2c9 ff9b fs9a fc2 sc0 ls0 ws0">Exp<span class="_ _5"></span>ressi ons<span class="_ _e"> </span>generated<span class="_ _16"> </span>b<span class="_ _5"></span>y<span class="_ _f"> </span><span class="ff9c">SELECT<span class="_ _16"> </span></span><span class="ls67">clauses</span></div><div class="t m1f x1a hcd y2ca ff9e fs9a fc2 sc0 ls0 ws0">A<span class="_ _15"> </span>and<span class="_ _15"> </span>B<span class="_ _25"> </span>must<span class="_ _15"> </span>have<span class="_ _15"> </span>com patib le<span class="_ _25"> </span>schema</div><div class="t m1f x9c hce y2cb ff9f fs99 fc2 sc0 ls0 ws0">select<span class="_ _1c"> </span>queries<span class="_ _17"> </span>must<span class="_ _1c"> </span>have<span class="_ _1c"> </span>the<span class="_ _1c"> </span>same<span class="_ _17"> </span>numb<span class="_ _9"></span>er<span class="_ _1c"> </span>o f<span class="_ _1c"> </span>o u tp u t<span class="_ _1c"> </span>fi e ld s ,<span class="_ _17"> </span>in<span class="_ _1c"> </span>the</div><div class="t m1f x9c hce y2cc ff9f fs99 fc2 sc0 ls0 ws0">same<span class="_ _1c"> </span>o<span class="_ _0"></span>rder,<span class="_ _1c"> </span>and<span class="_ _1c"> </span>with<span class="_ _1c"> </span>the<span class="_ _1c"> </span>sa me<span class="_ _17"> </span>o<span class="_ _5"></span>r<span class="_ _1c"> </span>co mp a tib le<span class="_ _17"> </span>data<span class="_ _1c"> </span>t<span class="_ _0"></span>yp<span class="_ _9"></span>es</div><div class="t m1f x1a hcd y2cd ff9b fs9a fc2 sc0 ls0 ws0">Duplicate<span class="_ _16"> </span>removal</div><div class="t m1f x9c hce y2ce ff9d fs99 fc2 sc0 ls0 ws0">UNION<span class="_ _1c"> </span><span class="ff9f ls68">removes<span class="_ _1c"> </span>duplica te s</span></div><div class="t m1f x9c hce y2cf ff9d fs99 fc2 sc0 ls0 ws0">UNION<span class="_ _48"> </span>ALL<span class="_ _60"> </span><span class="ff9f ls69">do<span class="_ _9"></span>es<span class="_ _1c"> </span>not<span class="_ _1c"> </span>remove<span class="_ _1c"> </span>duplicates</span></div><div class="t m1f x9d hcf y2d0 ffa0 fs9b fc1 sc0 ls6a ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _61"> </span>62<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="t m0 x4a h8 y2d1 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y2d2 ff2 fs0 fc2 sc0 ls0 ws0">A single <span class="ff5 ls12">SELECT</span> cannot r<span class="_ _0"></span>epr<span class="_ _0"></span>esent unions of values fr<span class="_ _0"></span>om two or </div><div class="t m0 x38 h2 y2d3 ff2 fs0 fc2 sc0 ls0 ws0">mor<span class="_ _0"></span>e tables </div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf27" class="step pf w0 h0" data-x="20500" data-y="0" data-scale="0.4" data-page-no="27"><div class="pc pc27 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg27.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">UNION<span class="ff3 ls0"> Example</span></div><div class="c x4a y2d4 w25 h2f"><div class="t m0 x29 hd0 ybe ff2 fs9c fc2 sc0 ls0 ws0">Find the code of r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts <span class="ff1 ls6b">OR</span> pr<span class="_ _0"></span>oducts supplied by S2 (or both) </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">39</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">1</span></div></div><div class="c x8f y2d5 w26 hd1"><div class="t m20 x7f hd2 y2d6 ffa1 fs9d fc4 sc0 ls6c ws0">UNION<span class="_ _3c"> </span><span class="ffa2 ls0">Example<span class="_ _30"> </span>on<span class="_ _3c"> </span>DB1</span></div><div class="t m20 x9e hd3 y2d7 ffa3 fs9e fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>the<span class="_ _f"> </span>c o<span class="_ _d"></span>de<span class="_ _15"> </span>of<span class="_ _15"> </span>red<span class="_ _f"> </span>p<span class="_ _0"></span>ro<span class="_ _d"></span>ducts<span class="_ _f"> </span><span class="ffa4 ls6d">OR<span class="_ _15"> </span></span><span class="ls6e">pr<span class="_ _d"></span>o<span class="_ _3f"></span>d<span class="_ _d"></span>u<span class="_ _d"></span>c<span class="_ _d"></span>t<span class="_ _9"></span>s<span class="_ _38"> </span>s<span class="_ _d"></span>u<span class="_ _9"></span>p<span class="_ _d"></span>p<span class="_ _d"></span>l<span class="_ _d"></span>i<span class="_ _d"></span>e<span class="_ _9"></span>d<span class="_ _38"> </span>by<span class="_ _38"> </span>S<span class="_ _9"></span>2<span class="_ _38"> </span>(<span class="_ _d"></span>or</span></div><div class="t m20 x9e hd3 y2d8 ffa3 fs9e fc2 sc0 ls0 ws0">b<span class="_ _d"></span>oth)</div><div class="t m20 x5 hd4 y2d9 ffa5 fs9f fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">CodeP</span></div><div class="t m20 x5 hd4 y2da ffa5 fs9f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Product</span></div><div class="t m20 x5 hd4 y2db ffa5 fs9f fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Colour<span class="_ _48"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"Red"</span></span></span></div><div class="t m20 x4d hd4 y2dc ffa5 fs9f fc5 sc0 ls0 ws0">UNION</div><div class="t m20 x5 hd4 y2dd ffa5 fs9f fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">CodeP</span></div><div class="t m20 x5 hd4 y2de ffa5 fs9f fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supply</span></div><div class="t m20 x5 hd4 y2df ffa5 fs9f fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">CodeS<span class="_ _48"> </span><span class="fc6">=<span class="_ _18"> </span><span class="fc7">"S2"</span></span></span></div><div class="t m20 x1 hd5 y2e0 ffa6 fsa0 fc1 sc0 ls6f ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _62"> </span>63<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf28" class="step pf w0 h0" data-x="21000" data-y="0" data-scale="0.4" data-page-no="28"><div class="pc pc28 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg28.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">UNION<span class="ff3 ls0"> Example</span></div><div class="c x4a ybd w25 h2f"><div class="t m0 x29 hd0 ybe ff2 fs9c fc2 sc0 ls0 ws0">Find the code of r<span class="_ _0"></span>ed pr<span class="_ _0"></span>oducts <span class="ff1 ls6b">OR</span> pr<span class="_ _0"></span>oducts supplied by S2 (or both) </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">40</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">1</span></div></div><div class="c x9f y0 w27 hd6"><div class="t m21 x54 hd7 y2e1 ffa7 fsa1 fc2 sc0 ls70 ws0">Coat</div><div class="t m21 x2 hd7 y2e2 ffa7 fsa1 fc2 sc0 ls0 ws0">Amsterdam<span class="_ _63"></span>Sweater</div><div class="t m21 xb hd7 y2e3 ffa7 fsa1 fc2 sc0 ls0 ws0">P4</div><div class="t m21 x2 hd7 y2e1 ffa7 fsa1 fc2 sc0 ls0 ws0">Amsterdam</div><div class="t m21 xa0 hd7 y2e4 ffa7 fsa1 fc2 sc0 ls70 ws0">Den Haag</div><div class="t m21 x3b hd7 y2e5 ffa7 fsa1 fc2 sc0 ls0 ws0">Blu</div><div class="t m21 xa1 hd7 y2e3 ffa7 fsa1 fc2 sc0 ls70 ws0">44</div><div class="t m21 xa2 hd7 y2e1 ffa7 fsa1 fc2 sc0 ls70 ws0">Red</div><div class="t m21 x2 hd7 y2e3 ffa7 fsa1 fc2 sc0 ls0 ws0">Amsterdam<span class="_ _64"></span>Blu</div><div class="t m21 xd hd8 y2e6 ffa8 fsa1 fc2 sc0 ls0 ws0">Size<span class="_ _65"></span><span class="ls70">Color</span></div><div class="t m21 xa2 hd7 y2e2 ffa7 fsa1 fc2 sc0 ls70 ws0">Red<span class="_ _66"> </span>40</div><div class="t m21 xa1 hd7 y2e1 ffa7 fsa1 fc2 sc0 ls70 ws0">42</div><div class="t m21 xa3 hd7 y2e7 ffa7 fsa1 fc2 sc0 ls0 ws0">Green<span class="_ _67"> </span><span class="ls70">Den Haag<span class="_ _68"></span><span class="ls0">Jeans</span></span></div><div class="t m21 x3b hd7 y2e4 ffa7 fsa1 fc2 sc0 ls0 ws0">Blu</div><div class="t m21 x1e hd8 y2e6 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeP</div><div class="t m21 x16 hd7 y2e4 ffa7 fsa1 fc2 sc0 ls0 ws0">Skirt</div><div class="t m21 xa1 hd7 y2e7 ffa7 fsa1 fc2 sc0 ls70 ws0">48</div><div class="t m21 xb hd7 y2e1 ffa7 fsa1 fc2 sc0 ls0 ws0">P6</div><div class="t m21 xb hd7 y2e7 ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div><div class="t m21 xa4 hd7 y2e5 ffa7 fsa1 fc2 sc0 ls0 ws0">Rotterdam</div><div class="t m21 x16 hd7 y2e3 ffa7 fsa1 fc2 sc0 ls0 ws0">Shirt</div><div class="t m21 x16 hd7 y2e5 ffa7 fsa1 fc2 sc0 ls0 ws0">Shirt</div><div class="t m21 x13 hd8 y2e6 ffa8 fsa1 fc2 sc0 ls70 ws0">NameP</div><div class="t m21 xa1 hd7 y2e4 ffa7 fsa1 fc2 sc0 ls70 ws0">40</div><div class="t m21 xb hd7 y2e2 ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xa1 hd7 y2e5 ffa7 fsa1 fc2 sc0 ls70 ws0">48</div><div class="t m21 xb hd7 y2e4 ffa7 fsa1 fc2 sc0 ls0 ws0">P5</div><div class="t m21 x4c hd8 y2e6 ffa8 fsa1 fc2 sc0 ls0 ws0">Storehouse</div><div class="t m21 xb hd7 y2e5 ffa7 fsa1 fc2 sc0 ls0 ws0">P3</div><div class="t m21 xa5 hd9 y2e8 ffa8 fsa2 fc2 sc0 ls0 ws0">Products</div><div class="t m21 x93 hd7 y2e9 ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xa6 hda y2ea ffa7 fsa3 fc2 sc0 ls71 ws0">300</div><div class="t m21 xa6 hda y2eb ffa7 fsa3 fc2 sc0 ls71 ws0">300</div><div class="t m21 x6e hd7 y2e9 ffa7 fsa1 fc2 sc0 ls70 ws0">300</div><div class="t m21 x93 hd7 y2ec ffa7 fsa1 fc2 sc0 ls0 ws0">P5</div><div class="t m21 xa6 hda y2ed ffa7 fsa3 fc2 sc0 ls71 ws0">400</div><div class="t m21 xa6 hda y2ee ffa7 fsa3 fc2 sc0 ls71 ws0">200</div><div class="t m21 x5f hd7 y2ef ffa7 fsa1 fc2 sc0 ls0 ws0">S3</div><div class="t m21 x72 hd8 y2f0 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeS</div><div class="t m21 xa6 hda y2f1 ffa7 fsa3 fc2 sc0 ls71 ws0">400</div><div class="t m21 x93 hd7 y2f2 ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div><div class="t m21 x5f hd7 y2e9 ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 x93 hd7 y2ef ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div><div class="t m21 xa6 hda y2f3 ffa7 fsa3 fc2 sc0 ls71 ws0">200</div><div class="t m21 x5f hd7 y2ec ffa7 fsa1 fc2 sc0 ls0 ws0">S4</div><div class="t m21 x5f hd7 y2f4 ffa7 fsa1 fc2 sc0 ls0 ws0">S4</div><div class="t m21 xa6 hda y2f5 ffa7 fsa3 fc2 sc0 ls71 ws0">200</div><div class="t m21 x5f hd7 y2f6 ffa7 fsa1 fc2 sc0 ls0 ws0">S2</div><div class="t m21 x5f hd7 y2f7 ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 x5f hd7 y2f8 ffa7 fsa1 fc2 sc0 ls0 ws0">S2</div><div class="t m21 xa6 hda y2f9 ffa7 fsa3 fc2 sc0 ls71 ws0">100</div><div class="t m21 x5f hd7 y2fa ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 x93 hd7 y2fb ffa7 fsa1 fc2 sc0 ls0 ws0">P5</div><div class="t m21 xa6 hda y2fc ffa7 fsa3 fc2 sc0 ls71 ws0">100</div><div class="t m21 x93 hd7 y2f6 ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div><div class="t m21 x1a hd8 y2f0 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeP</div><div class="t m21 x5f hd7 y2fd ffa7 fsa1 fc2 sc0 ls0 ws0">S4</div><div class="t m21 x5f hd7 y2f2 ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 x5f hd7 y2fb ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 xa6 hda y2fe ffa7 fsa3 fc2 sc0 ls71 ws0">400</div><div class="t m21 x93 hd7 y2f7 ffa7 fsa1 fc2 sc0 ls0 ws0">P6</div><div class="t m21 x93 hd7 y2fa ffa7 fsa1 fc2 sc0 ls0 ws0">P4</div><div class="t m21 xa6 hda y2ff ffa7 fsa3 fc2 sc0 ls71 ws0">200</div><div class="t m21 x93 hd7 y2f4 ffa7 fsa1 fc2 sc0 ls0 ws0">P3</div><div class="t m21 x93 hd7 y2fd ffa7 fsa1 fc2 sc0 ls0 ws0">P4</div><div class="t m21 x93 hd7 y300 ffa7 fsa1 fc2 sc0 ls0 ws0">P3</div><div class="t m21 x93 hd7 y2f8 ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xa7 hd8 y2f0 ffa8 fsa1 fc2 sc0 ls70 ws0">Amount</div><div class="t m21 x5f hd7 y300 ffa7 fsa1 fc2 sc0 ls0 ws0">S1</div><div class="t m21 x1a hd9 y301 ffa8 fsa2 fc2 sc0 ls0 ws0">Supply</div><div class="t m21 xa8 hd8 y302 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeP</div><div class="t m21 xa9 hd7 y303 ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xa9 hd7 y304 ffa7 fsa1 fc2 sc0 ls0 ws0">P6</div><div class="t m21 xa8 hd8 y305 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeP</div><div class="t m21 xa9 hd7 y306 ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xa9 hd7 y307 ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div><div class="t m21 xaa hd7 y308 ffa7 fsa1 fc2 sc0 ls0 ws0">P6</div><div class="t m21 xab hd8 y309 ffa8 fsa1 fc2 sc0 ls70 ws0">CodeP</div><div class="t m21 xaa hd7 y30a ffa7 fsa1 fc2 sc0 ls0 ws0">P1</div><div class="t m21 xaa hd7 y30b ffa7 fsa1 fc2 sc0 ls0 ws0">P2</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf29" class="step pf w0 h0" data-x="21500" data-y="0" data-scale="0.4" data-page-no="29"><div class="pc pc29 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg29.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">UNION<span class="ff3 ls0"> Example</span></div><div class="c x4a ybd w14 h2f"><div class="t m0 x14 h2 y30c ff2 fs0 fc2 sc0 ls0 ws0">Find the first names and sur<span class="_ _9"></span>names of the employees </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">41</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">2</span></div></div><div class="c xb y3 w28 hdb"><div class="t m22 x8c hdc y30d ffa9 fsa4 fc4 sc0 ls72 ws0">UNION<span class="_ _30"> </span><span class="ffaa ls0">Exampl e<span class="_ _69"> </span>from<span class="_ _30"> </span>DB 2</span></div><div class="t m22 x13 hdd y30e ffab fsa5 fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>the<span class="_ _25"> </span>first<span class="_ _25"> </span>names<span class="_ _25"> </span>and<span class="_ _15"> </span>su rn am es<span class="_ _25"> </span>of<span class="_ _25"> </span>the<span class="_ _15"> </span>emp lo<span class="_ _0"></span>y<span class="_ _5"></span>ees</div><div class="t m22 x8a hde y30f ffac fsa6 fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">FirstName<span class="_ _26"> </span></span>as<span class="_ _26"> </span><span class="fc2">Name</span></div><div class="t m22 x8a hde y310 ffac fsa6 fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Employee</span></div><div class="t m22 x1f hde y311 ffac fsa6 fc5 sc0 ls0 ws0">UNION</div><div class="t m22 x8a hde y312 ffac fsa6 fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">Surname</span></div><div class="t m22 x8a hde y313 ffac fsa6 fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Employee</span></div><div class="t m22 xac hdf y314 ffad fsa7 fc1 sc0 ls73 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _1a"> </span>Queries<span class="_ _6a"> </span>65<span class="_ _4e"> </span>/<span class="_ _1a"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-new2" class="step" data-x="22000" data-y="0" data-scale="0.4" data-timer="30">
<asq-exercise style="height: 420px; padding: 20px 20px; background: rgba(255, 255, 255, 0.8); margin-top: 40px;">
<asq-stem class="small"><h4><b>How can we get all tuples (redundant as well as non-redundant) from UNION operator?</b></h4>
</asq-stem>
<asq-multi-choice-q>
<asq-stem class="hidden"><h4>How can we get all tuples (redundant as well as non-redundant) from UNION operator?</h4>
</asq-stem>
<asq-option class="smaller" style="display: block;" name="a" correct>Using ‘ALL’ operator with UNION</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="b">Using ‘Distinct’ operator with UNION</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="c">We get all records (redundant as well as nonredundant) with UNION operator by default</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="d">None of the above</asq-option>
</asq-multi-choice-q>
</asq-exercise>
<div class="flickr-credit">flickr@nasacommons</div>
</div>
<div id="pf2a" class="step pf w0 h0" data-x="22500" data-y="0" data-scale="0.4" data-page-no="2a"><div class="pc pc2a w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2a.png"/><div class="t m0 x5 hc4 y5 ff5 fs2 fc2 sc0 ls21 ws0">INTERSECTION</div><div class="t m0 x4a h8 y315 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y28 ff2 fs0 fc2 sc0 ls0 ws0">Intersection of two subqueries </div><div class="t m0 x4a h8 y316 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y88 ff2 fs0 fc2 sc0 ls0 ws0">As for the <span class="ff5 ls12">UNION</span> operator<span class="_ _6"></span>, schema must be compatible </div><div class="t m0 x4a h8 y317 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y318 ff2 fs0 fc2 sc0 ls0 ws0">Not suppor<span class="_ _9"></span>ted by MySQL </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">42</div><div class="c x5e y319 w29 he0"><div class="t m23 x47 he1 y31a ffae fsa8 fc4 sc0 ls0 ws0">In<span class="_ _3"></span>tersection</div><div class="t m23 x3f he2 y31b ffaf fsa9 fc2 sc0 ls0 ws0">A<span class="_ _18"> </span>INTERSECT<span class="_ _18"> </span>B</div><div class="t m23 x72 he3 y31c ffb0 fsaa fc2 sc0 ls0 ws0">Intersection<span class="_ _f"> </span>of<span class="_ _15"> </span>t<span class="_ _5"></span>w<span class="_ _5"></span>o<span class="_ _15"> </span>sub<span class="_ _d"></span>queries</div><div class="t m23 x72 he3 y31d ffb0 fsaa fc2 sc0 ls74 ws0">as<span class="_ _f"> </span>fo<span class="_ _5"></span>r<span class="_ _f"> </span>the<span class="_ _f"> </span><span class="ffb1 ls0">UNION<span class="_ _15"> </span><span class="ffb0">op<span class="_ _d"></span>erato<span class="_ _5"></span>r,<span class="_ _f"> </span>schema<span class="_ _15"> </span>must<span class="_ _f"> </span>b<span class="_ _d"></span>e<span class="_ _f"> </span>compatibl e</span></span></div><div class="t m23 x72 he3 y31e ffb0 fsaa fc2 sc0 ls0 ws0">Not<span class="_ _f"> </span>supp<span class="_ _d"></span>o<span class="_ _5"></span>rted<span class="_ _15"> </span>b<span class="_ _5"></span>y<span class="_ _f"> </span>MySQL</div><div class="t m23 x8b he4 y31f ffb2 fsab fc1 sc0 ls75 ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6b"> </span>66<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf2b" class="step pf w0 h0" data-x="23000" data-y="0" data-scale="0.4" data-page-no="2b"><div class="pc pc2b w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2b.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">INTERSECT<span class="ff3 ls0"> Example</span></div><div class="c x4a ybd w2a h2f"><div class="t m0 x61 he5 ybe ff2 fs9c fc2 sc0 ls0 ws0">Find cities hosting both suppliers’ of<span class="_ _0"></span>fices and pr<span class="_ _0"></span>oducts’ stor<span class="_ _0"></span>ehouses </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">43</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">1</span></div></div><div class="c x8f y320 w26 h60"><div class="t m24 x53 he6 y321 ffb3 fsac fc4 sc0 ls76 ws0">INTERSECT<span class="_ _30"> </span><span class="ffb4 ls0">Example<span class="_ _30"> </span>from<span class="_ _3c"> </span>D B1</span></div><div class="t m24 x9e he7 y322 ffb5 fsad fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>cities<span class="_ _15"> </span>host in g<span class="_ _15"> </span>b<span class="_ _d"></span>oth<span class="_ _15"> </span>sup p l ie r s’<span class="_ _25"> </span>o<span class="ffb6">ffi</span><span class="ls77">ces<span class="_ _15"> </span>and<span class="_ _15"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts’</span></div><div class="t m24 x9e he7 y323 ffb5 fsad fc2 sc0 ls0 ws0">sto<span class="_ _5"></span>rehouses</div><div class="t m24 x8a he8 y324 ffb7 fsae fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">Office</span></div><div class="t m24 x8a he8 y325 ffb7 fsae fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Supplier</span></div><div class="t m24 x97 he8 y326 ffb7 fsae fc5 sc0 ls0 ws0">INTERSECT</div><div class="t m24 x8a he8 y327 ffb7 fsae fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">Storehouse</span></div><div class="t m24 x8a he8 y328 ffb7 fsae fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Product</span></div><div class="t m24 x9e he7 y329 ffb5 fsad fc2 sc0 ls11 ws0">Equivalent<span class="_ _15"> </span>to</div><div class="t m24 x27 he8 y32a ffb7 fsae fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">Office</span></div><div class="t m24 x27 he8 y32b ffb7 fsae fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Supplier,<span class="_ _48"> </span>Product</span></div><div class="t m24 x27 he8 y32c ffb7 fsae fc5 sc0 ls0 ws0">WHERE<span class="_ _48"> </span><span class="fc2">Office<span class="_ _48"> </span><span class="fc6">=<span class="_ _48"> </span></span>Storehouse</span></div><div class="t m24 xad he9 y32d ffb8 fsaf fc1 sc0 ls78 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6c"> </span>67<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="c x8f y32e w26 hea"><div class="t m25 x7b heb y32f ffb9 fsb0 fc4 sc0 ls79 ws0">INTERSECT<span class="_ _3c"> </span><span class="ffba ls0">Exa m ple<span class="_ _30"> </span>from<span class="_ _30"> </span>DB1</span></div><div class="t m25 x15 hec y330 ffbb fsb1 fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>cities<span class="_ _15"> </span>hosting<span class="_ _15"> </span>b<span class="_ _d"></span>oth<span class="_ _15"> </span>suppli er s’<span class="_ _15"> </span>o<span class="ffbc">ffi </span><span class="ls7a">ces<span class="_ _15"> </span>and<span class="_ _15"> </span>p<span class="_ _0"></span>ro<span class="_ _9"></span>ducts’</span></div><div class="t m25 x15 hec y331 ffbb fsb1 fc2 sc0 ls0 ws0">sto<span class="_ _5"></span>rehouses</div><div class="t m25 x46 hed y332 ffbd fsb2 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Office</span></div><div class="t m25 x46 hed y333 ffbd fsb2 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier</span></div><div class="t m25 x4d hed y334 ffbd fsb2 fc5 sc0 ls0 ws0">INTERSECT</div><div class="t m25 x46 hed y335 ffbd fsb2 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Storehouse</span></div><div class="t m25 x46 hed y336 ffbd fsb2 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Product</span></div><div class="t m25 x15 hec y337 ffbb fsb1 fc2 sc0 ls7b ws0">Equivalent<span class="_ _15"> </span>to</div><div class="t m25 x61 hed y338 ffbd fsb2 fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Office</span></div><div class="t m25 x61 hed y339 ffbd fsb2 fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Supplier,<span class="_ _48"> </span>Product</span></div><div class="t m25 x61 hed y33a ffbd fsb2 fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">Office<span class="_ _48"> </span><span class="fc6">=<span class="_ _48"> </span></span>Storehouse</span></div><div class="t m25 x9d hee y33b ffbe fsb3 fc1 sc0 ls7c ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6d"> </span>67<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="t m0 x4a h8 y33c ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y13 ff2 fs0 fc2 sc0 ls0 ws0">Equivalent to</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf2c" class="step pf w0 h0" data-x="23500" data-y="0" data-scale="0.4" data-page-no="2c"><div class="pc pc2c w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2c.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">INTERSECT<span class="ff3 ls0"> Example /2</span></div><div class="c x4a ybd w14 h2f"><div class="t m0 x6b h2 y30c ff2 fs0 fc2 sc0 ls0 ws0">Find the sur<span class="_ _9"></span>names of employees that ar<span class="_ _0"></span>e also first names </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">44</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">2</span></div></div><div class="t m0 x4a h8 y33c ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y13 ff2 fs0 fc2 sc0 ls0 ws0">Equivalent to</div><div class="c x36 yb9 w2b hef"><div class="t m26 x43 hf0 y33d ffbf fsb4 fc4 sc0 ls7d ws0">INTERSECT<span class="_ _30"> </span><span class="ffc0 ls0">Example<span class="_ _30"> </span>from<span class="_ _30"> </span>DB2</span></div><div class="t m26 x72 hf1 y33e ffc1 fsb5 fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>the<span class="_ _15"> </span>surn a mes<span class="_ _25"> </span>of<span class="_ _15"> </span>emplo<span class="_ _5"></span>y<span class="_ _0"></span>ees<span class="_ _f"> </span>th at<span class="_ _25"> </span>a<span class="_ _5"></span>re<span class="_ _15"> </span>also<span class="_ _15"> </span>fir st<span class="_ _25"> </span>names:</div><div class="t m26 x4a hf2 y33f ffc2 fsb6 fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">FirstName<span class="_ _48"> </span></span>as<span class="_ _48"> </span><span class="fc2">Name</span></div><div class="t m26 x4a hf2 y340 ffc2 fsb6 fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Employee</span></div><div class="t m26 x71 hf2 y341 ffc2 fsb6 fc5 sc0 ls0 ws0">INTERSECT</div><div class="t m26 x4a hf2 y342 ffc2 fsb6 fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">Surname</span></div><div class="t m26 x4a hf2 y343 ffc2 fsb6 fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Employee</span></div><div class="t m26 x72 hf1 y344 ffc1 fsb5 fc2 sc0 ls7e ws0">Equivalent<span class="_ _15"> </span>to</div><div class="t m26 x23 hf2 y345 ffc2 fsb6 fc5 sc0 ls0 ws0">SELECT<span class="_ _48"> </span><span class="fc2">E1.FirstName<span class="_ _48"> </span></span>as<span class="_ _48"> </span><span class="fc2">Name</span></div><div class="t m26 x23 hf2 y346 ffc2 fsb6 fc5 sc0 ls0 ws0">FROM<span class="_ _48"> </span><span class="fc2">Employee<span class="_ _48"> </span>E1,<span class="_ _48"> </span>Employee<span class="_ _48"> </span>E2</span></div><div class="t m26 x23 hf2 y347 ffc2 fsb6 fc5 sc0 ls0 ws0">WHERE<span class="_ _48"> </span><span class="fc2">E1.FirstName<span class="_ _48"> </span><span class="fc6">=<span class="_ _48"> </span></span>E2.Surname</span></div><div class="t m26 xac hf3 y348 ffc3 fsb7 fc1 sc0 ls7f ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6e"> </span>68<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="c x92 y349 w1a hf4"><div class="t m27 x7f hf5 y34a ffc4 fsb8 fc4 sc0 ls80 ws0">INTERSECT<span class="_ _3c"> </span><span class="ffc5 ls0">Example<span class="_ _30"> </span>from<span class="_ _3c"> </span>DB2</span></div><div class="t m27 x9e hf6 y34b ffc6 fsb9 fc2 sc0 ls0 ws0">Find<span class="_ _15"> </span>the<span class="_ _f"> </span>s ur n am es<span class="_ _15"> </span>of<span class="_ _15"> </span>emplo<span class="_ _5"></span>y<span class="_ _0"></span>ees<span class="_ _f"> </span>that<span class="_ _15"> </span>a<span class="_ _5"></span>r e<span class="_ _15"> </span>also<span class="_ _15"> </span>first<span class="_ _15"> </span>names:</div><div class="t m27 x5 hf7 y34c ffc7 fsba fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">FirstName<span class="_ _48"> </span></span>as<span class="_ _18"> </span><span class="fc2">Name</span></div><div class="t m27 x5 hf7 y34d ffc7 fsba fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m27 x4d hf7 y34e ffc7 fsba fc5 sc0 ls0 ws0">INTERSECT</div><div class="t m27 x5 hf7 y34f ffc7 fsba fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">Surname</span></div><div class="t m27 x5 hf7 y350 ffc7 fsba fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee</span></div><div class="t m27 x9e hf6 y351 ffc6 fsb9 fc2 sc0 ls81 ws0">Equivalent<span class="_ _15"> </span>to</div><div class="t m27 x29 hf7 y352 ffc7 fsba fc5 sc0 ls0 ws0">SELECT<span class="_ _18"> </span><span class="fc2">E1.FirstName<span class="_ _48"> </span></span>as<span class="_ _18"> </span><span class="fc2">Name</span></div><div class="t m27 x29 hf7 y353 ffc7 fsba fc5 sc0 ls0 ws0">FROM<span class="_ _18"> </span><span class="fc2">Employee<span class="_ _48"> </span>E1,<span class="_ _18"> </span>Employee<span class="_ _48"> </span>E2</span></div><div class="t m27 x29 hf7 y354 ffc7 fsba fc5 sc0 ls0 ws0">WHERE<span class="_ _18"> </span><span class="fc2">E1.FirstName<span class="_ _48"> </span><span class="fc6">=<span class="_ _18"> </span></span>E2.Surname</span></div><div class="t m27 x8b hf8 y355 ffc8 fsbb fc1 sc0 ls82 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _62"> </span>68<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf2d" class="step pf w0 h0" data-x="24000" data-y="0" data-scale="0.4" data-page-no="2d"><div class="pc pc2d w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2d.png"/><div class="t m0 x5 hc4 y5 ff5 fs2 fc2 sc0 ls21 ws0">EXCEPT</div><div class="t m0 x4a h8 y356 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y357 ff6 fs0 fc2 sc0 ls0 ws0">Dif<span class="_ _0"></span>fer<span class="_ _0"></span>ence<span class="ff2"> set operator </span></div><div class="t m0 x4a h8 y358 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x38 h2 y124 ff2 fs0 fc2 sc0 ls0 ws0">Not suppor<span class="_ _9"></span>ted by MySQL </div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">45</div><div class="c x92 y359 w2c hf9"><div class="t m28 x7f hfa y35a ffc9 fsbc fc4 sc0 ls83 ws0">EXCEPT</div><div class="t m28 x9e hfb y35b ffca fsbd fc2 sc0 ls84 ws0">Di<span class="ffcb ls0">↵</span>erence<span class="_ _1d"> </span><span class="ffcc ls0">set<span class="_ _15"> </span>op<span class="_ _d"></span>erato<span class="_ _5"></span>r</span></div><div class="t m28 x9e hfb y35c ffcc fsbd fc2 sc0 ls0 ws0">Not<span class="_ _15"> </span>supp<span class="_ _d"></span>o<span class="_ _5"></span>rted<span class="_ _15"> </span>b<span class="_ _5"></span>y<span class="_ _15"> </span>MySQL</div><div class="t m28 x29 hfc y35d ffcd fsbe fc2 sc0 ls0 ws0">A<span class="_ _18"> </span><span class="fc5">EXCEPT<span class="_ _48"> </span></span>B</div><div class="t m28 x86 hfd y35e ffce fsbf fc1 sc0 ls85 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6d"> </span>69<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-7" class="step" data-x="24500" data-y="0" data-scale="0.4" data-timer="45">
<asq-exercise>
<asq-stem class="smaller"><h4>Which statement best described the meaning of the following SQL query on the CHINOOK database?<a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
<pre class="sql"><code>SELECT artistId, name FROM artist
EXCEPT
SELECT artist.artistId, artist.name
FROM artist, album
WHERE artist.artistId = album.artistId
</code></pre>
</asq-stem>
<asq-multi-choice-q>
<asq-stem class="hidden"><h4>Q.7 - Which statement best described the meaning of the following SQL query on the CHINOOK database?<a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
<pre class="sql"><code>SELECT artistId, name FROM artist
EXCEPT
SELECT artist.artistId, artist.name
FROM artist, album
WHERE artist.artistId = album.artistId
</code></pre>
</asq-stem>
<asq-option class="smaller" style="display: block;" name="a">Retrieve the id and name of artists that published at
least one album</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="b">Retrieve the id and name of artists that published more than one albums</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="c" correct>Retrieve the id and name of artists that published no album</asq-option>
<asq-option class="smaller" style="display: block; margin-top: 20px;" name="d">Retrieve the id and name of artists that published with other artists</asq-option>
</asq-multi-choice-q>
</asq-exercise>
</div>
<div id="pf2e" class="step pf w0 h0" data-x="25000" data-y="0" data-scale="0.4" data-page-no="2e"><div class="pc pc2e w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2e.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">EXCEPT<span class="ff3 ls0"> Example</span></div><div class="c x4a ybd w2d h2f"><div class="t m0 x61 hfe y30c ff2 fsc0 fc2 sc0 ls0 ws0">Find cities hosting suppliers’ of<span class="_ _0"></span>fices, but not pr<span class="_ _0"></span>oducts’ stor<span class="_ _0"></span>ehouses </div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">46</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">1</span></div></div><div class="t m0 x4a hff y35f ff2 fsc1 fc2 sc0 ls0 ws0">•</div><div class="t m0 x1c he5 y360 ff2 fs9c fc2 sc0 ls0 ws0">Can be r<span class="_ _0"></span>epr<span class="_ _0"></span>esented with a nested quer<span class="_ _9"></span>y using the NOT IN operator</div><div class="c x36 y361 w2e h100"><div class="t m29 x5a h101 y362 ffcf fsc2 fc4 sc0 ls86 ws0">EXCEPT<span class="_ _30"> </span><span class="ffd0 ls0">Example<span class="_ _30"> </span>from<span class="_ _30"> </span>DB1</span></div><div class="t m29 x12 h102 y363 ffd1 fsc3 fc2 sc0 ls0 ws0">Find<span class="_ _16"> </span>cities<span class="_ _16"> </span>hosting<span class="_ _17"> </span>s up p l i er s’<span class="_ _16"> </span>o<span class="ffd2">ffi</span>ces,<span class="_ _16"> </span>but<span class="_ _16"> </span>not<span class="_ _16"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts’<span class="_ _16"> </span>sto<span class="_ _5"></span>rehouses</div><div class="t m29 x1e h103 y364 ffd3 fsc4 fc5 sc0 ls0 ws0">SELECT<span class="_ _5a"> </span><span class="fc2">Office</span></div><div class="t m29 xb h103 y365 ffd3 fsc4 fc5 sc0 ls0 ws0">FROM<span class="_ _5a"> </span><span class="fc2">Supplier</span></div><div class="t m29 x1e h103 y366 ffd3 fsc4 fc5 sc0 ls0 ws0">EXCEPT</div><div class="t m29 xb h103 y367 ffd3 fsc4 fc5 sc0 ls0 ws0">SELECT<span class="_ _5a"> </span><span class="fc2">Storehouse</span></div><div class="t m29 xb h103 y368 ffd3 fsc4 fc5 sc0 ls0 ws0">FROM<span class="_ _5a"> </span><span class="fc2">Product</span></div><div class="t m29 x12 h102 y369 ffd1 fsc3 fc2 sc0 ls87 ws0">Can<span class="_ _16"> </span>b<span class="_ _9"></span>e<span class="_ _16"> </span>rep<span class="_ _0"></span>resented<span class="_ _16"> </span>with<span class="_ _16"> </span>a<span class="_ _17"> </span>neste<span class="_ _33"></span>d<span class="_ _16"> </span>query<span class="_ _16"> </span>using<span class="_ _17"> </span>th e<span class="_ _16"> </span><span class="ffd4 ls88">NOT<span class="_ _17"> </span>I N<span class="_ _21"> </span></span><span class="ls0">op<span class="_ _d"></span>erato<span class="_ _5"></span>r</span></div><div class="t m29 x5b h103 y36a ffd3 fsc4 fc5 sc0 ls0 ws0">SELECT<span class="_ _5a"> </span><span class="fc2">Office</span></div><div class="t m29 x5b h103 y36b ffd3 fsc4 fc5 sc0 ls0 ws0">FROM<span class="_ _5a"> </span><span class="fc2">Supplier</span></div><div class="t m29 x5b h103 y36c ffd3 fsc4 fc5 sc0 ls0 ws0">WHERE<span class="_ _5a"> </span><span class="fc2">Office<span class="_ _57"> </span></span>NOT<span class="_ _5a"> </span>IN<span class="_ _57"> </span><span class="fc2">(</span>SELECT<span class="_ _5a"> </span><span class="fc2">Storehouse</span></div><div class="t m29 xae h103 y36d ffd3 fsc4 fc5 sc0 ls0 ws0">FROM<span class="_ _5a"> </span><span class="fc2">Product)</span></div><div class="t m29 x9d h104 y36e ffd5 fsc5 fc1 sc0 ls89 ws0">Advanced<span class="_ _4e"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _6f"> </span>70<span class="_ _4e"> </span>/<span class="_ _4e"> </span>74</div></div><div class="c x5e y36f w1a ha0"><div class="t m2a x53 h105 y370 ffd6 fsc6 fc4 sc0 ls8a ws0">EXCEPT<span class="_ _2d"> </span><span class="ffd7 ls0">Ex a mpl e<span class="_ _3c"> </span>from<span class="_ _3c"> </span>DB1</span></div><div class="t m2a x12 h106 y371 ffd8 fsc7 fc2 sc0 ls0 ws0">Find<span class="_ _17"> </span>cities<span class="_ _16"> </span>hosting<span class="_ _17"> </span>suppliers’<span class="_ _16"> </span>o<span class="ffd9">ffi</span>ces,<span class="_ _17"> </span>but<span class="_ _17"> </span>not<span class="_ _16"> </span>p<span class="_ _5"></span>ro<span class="_ _d"></span>ducts’<span class="_ _17"> </span>sto<span class="_ _0"></span>rehouses</div><div class="t m2a x1f h107 y372 ffda fsc8 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">Office</span></div><div class="t m2a x36 h107 y373 ffda fsc8 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supplier</span></div><div class="t m2a x1f h107 y374 ffda fsc8 fc5 sc0 ls0 ws0">EXCEPT</div><div class="t m2a x36 h107 y375 ffda fsc8 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">Storehouse</span></div><div class="t m2a x36 h107 y376 ffda fsc8 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Product</span></div><div class="t m2a x12 h106 y377 ffd8 fsc7 fc2 sc0 ls8b ws0">Can<span class="_ _17"> </span>b<span class="_ _d"></span>e<span class="_ _17"> </span>rep<span class="_ _0"></span>resented<span class="_ _17"> </span>wi th<span class="_ _16"> </span>a<span class="_ _17"> </span>nested<span class="_ _17"> </span>q u e r y<span class="_ _16"> </span>using<span class="_ _17"> </span>the<span class="_ _17"> </span><span class="ffdb ls8c">NOT<span class="_ _17"> </span>IN<span class="_ _21"> </span></span><span class="ls0">op<span class="_ _9"></span>erato<span class="_ _0"></span>r</span></div><div class="t m2a xe h107 y378 ffda fsc8 fc5 sc0 ls0 ws0">SELECT<span class="_ _21"> </span><span class="fc2">Office</span></div><div class="t m2a xe h107 y379 ffda fsc8 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Supplier</span></div><div class="t m2a xe h107 y37a ffda fsc8 fc5 sc0 ls0 ws0">WHERE<span class="_ _21"> </span><span class="fc2">Office<span class="_ _5a"> </span></span>NOT<span class="_ _21"> </span>IN<span class="_ _5a"> </span><span class="fc2">(</span>SELECT<span class="_ _21"> </span><span class="fc2">Storehouse</span></div><div class="t m2a xaf h107 y37b ffda fsc8 fc5 sc0 ls0 ws0">FROM<span class="_ _21"> </span><span class="fc2">Product)</span></div><div class="t m2a x5d h108 y37c ffdc fsc9 fc1 sc0 ls8d ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _70"> </span>70<span class="_ _2b"> </span>/<span class="_ _4e"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf2f" class="step pf w0 h0" data-x="25500" data-y="0" data-scale="0.4" data-page-no="2f"><div class="pc pc2f w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg2f.png"/><div class="t m0 x5 h4 y5 ff5 fs2 fc2 sc0 ls21 ws0">EXCEPT<span class="ff3 ls0"> Example /2</span></div><div class="c x4a ybd w14 h2f"><div class="t m0 x46 h2 y30c ff2 fs0 fc2 sc0 ls0 ws0">Find the sur<span class="_ _9"></span>names of employees that ar<span class="_ _0"></span>e not also first names</div></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">47</div><div class="c x1d y52 w5 h13"><div class="t m0 x1e h14 y53 ff1 fsb fc1 sc0 ls6 ws0">DB<span class="ls0">2</span></div></div><div class="c x92 y37d w1a hdb"><div class="t m2b x43 h109 y37e ffdd fsca fc4 sc0 ls8e ws0">EXCEPT<span class="_ _29"> </span><span class="ffde ls0">Ex a mpl e<span class="_ _2d"> </span>from<span class="_ _2d"> </span>DB2</span></div><div class="t m2b x9e h10a y37f ffdf fscb fc2 sc0 ls0 ws0">Find<span class="_ _f"> </span>the<span class="_ _f"> </span>surnames<span class="_ _f"> </span>of<span class="_ _f"> </span>emplo<span class="_ _0"></span>y<span class="_ _5"></span>ees<span class="_ _f"> </span>that<span class="_ _f"> </span>a<span class="_ _5"></span>re<span class="_ _f"> </span>not<span class="_ _f"> </span>also<span class="_ _f"> </span>first<span class="_ _f"> </span>names:</div><div class="t m2b x46 h10b y380 ffe0 fscc fc5 sc0 ls0 ws0">SELECT<span class="_ _2a"> </span><span class="fc2">FirstName<span class="_ _18"> </span></span>as<span class="_ _18"> </span><span class="fc2">Name</span></div><div class="t m2b x46 h10b y381 ffe0 fscc fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Employee</span></div><div class="t m2b xb0 h10b y382 ffe0 fscc fc5 sc0 ls0 ws0">EXCEPT</div><div class="t m2b x46 h10b y383 ffe0 fscc fc5 sc0 ls0 ws0">SELECT<span class="_ _2a"> </span><span class="fc2">Surname</span></div><div class="t m2b x46 h10b y384 ffe0 fscc fc5 sc0 ls0 ws0">FROM<span class="_ _2a"> </span><span class="fc2">Employee</span></div><div class="t m2b x5d h10c y385 ffe1 fscd fc1 sc0 ls8f ws0">Advanced<span class="_ _2b"> </span>SQL<span class="_ _4e"> </span>Queries<span class="_ _4d"> </span>71<span class="_ _2b"> </span>/<span class="_ _2b"> </span>74</div></div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-8" class="step pf w0 h0" data-x="26000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Which artists did not record any tracks of the Latin genre? <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.8 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Which artists did not record any tracks of the Latin genre? <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT artistId, name FROM artist
EXCEPT
SELECT artist.artistId, artist.name
FROM artist, album, track, genre
WHERE artist.artistId = album.artistId
AND album.albumId = track.albumId
AND track.genreId = genre.genreId
AND genre.name = 'Latin'</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="pf33" class="step pf w0 h0" data-x="26500" data-y="0" data-scale="0.4" data-page-no="33"><div class="pc pc33 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg33.png"/><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">T<span class="_ _45"></span>oda<span class="_ _a"></span>y w<span class="_ _3"></span>e co<span class="_ _0"></span>v<span class="_ _3"></span>er<span class="_ _5"></span>ed</div><div class="t m0 x6 h114 y3ad ff2 fsd1 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h5 y3ae ff2 fs3 fc2 sc0 ls0 ws0">Nested Queries </div><div class="t m0 x6 h114 y3af ff2 fsd1 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h5 y3b0 ff2 fs3 fc2 sc0 ls0 ws0">Set Queries</div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">51</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf34" class="step pf w0 h0" data-x="27000" data-y="0" data-scale="0.4" data-page-no="34"><div class="pc pc34 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg34.png"/><div class="t m0 x6 h8 y3b1 ff2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h1 y3b2 ff1 fs0 fc2 sc0 ls0 ws0">Database <span class="ls11">Book</span></div><div class="t m0 x16 h115 y3b3 ffe2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x3d h2 y237 ff6 fs0 fc2 sc0 ls0 ws0">Chapter 4 </div><div class="t m0 x16 h115 y3b4 ffe2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x3d h2 y3b5 ff6 fs0 fc2 sc0 ls0 ws0">Chapter 5<span class="ff2"> </span></div><div class="t m0 x6 h115 y3b6 ffe2 fs5 fc2 sc0 ls0 ws0">•</div><div class="t m0 x9 h1 y3b7 ff1 fs0 fc2 sc0 ls0 ws0">Suggested Readings on <span class="ls11">Blackboard</span></div><div class="t m0 x3e h7 y16 ff2 fs4 fc2 sc0 ls0 ws0">52</div><div class="t m0 x5 h4 y5 ff3 fs2 fc2 sc0 ls0 ws0">Readings</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="pf35" class="step pf w0 h0" data-x="27500" data-y="0" data-scale="0.4" data-page-no="35"><div class="pc pc35 w0 h0"><img class="bi x0 y0 w0 h0" alt="" src="img/bg/bg35.png"/><div class="t m0 xb4 he y28 ff3 fs8 fc2 sc0 ls0 ws0">End of Lectur<span class="_ _47"></span>e</div></div><div class="pi" data-data='{"ctm":[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
<div id="asq-9" class="step pf w0 h0" data-x="28000" data-y="0" data-scale="0.4" data-timer="300"style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>List the genre of tracks which are contained in the most playlists. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Ex.9 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>List the genre of tracks which are contained in the most playlists. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT Genre.GenreId, Genre.Name, COUNT(Distinct PlaylistId)
FROM Genre, Track, PlaylistTrack
WHERE Genre.GenreId=Track.GenreID AND
Track.TrackId = PlaylistTrack.TrackId
GROUP BY Genre.GenreId, Genre.Name
HAVING COUNT(Distinct PlaylistId) = (
SELECT MAX(aux.count)
FROM (SELECT COUNT(Distinct PlaylistId) as count
FROM Genre, Track, PlaylistTrack
WHERE Genre.GenreId=Track.GenreID AND Track.TrackId = PlaylistTrack.TrackId
GROUP BY Genre.GenreId, Genre.Name) AS aux)</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="asq-10" class="step pf h0 w0" data-x="28500" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the name of the playlist(s) that contain the largest number of pop tracks. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.11 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the name of the playlist(s) that contain the largest number of pop tracks. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT P.PlaylistId, P.Name
FROM Playlist as P, PlaylistTrack as PL, Track, MediaType, Genre
WHERE MediaType.Name LIKE '%audio%' AND P.PlaylistId = PL.PlaylistId
AND PL.TrackId = Track.TrackId
AND Track.MediaTypeId = MediaType.MediaTypeId
AND Track.GenreId = Genre.GenreID AND Genre.Name='Pop'
GROUP BY P.PlaylistId, P.Name
HAVING COUNT(*) = (SELECT MAX(aux.count)
FROM (SELECT COUNT(*) as count
FROM Playlist as P, PlaylistTrack as PL, Track, MediaType, Genre
WHERE MediaType.Name LIKE '%audio%' AND P.PlaylistId = PL.PlaylistId
AND PL.TrackId = Track.TrackId
AND Track.MediaTypeId = MediaType.MediaTypeId
AND Track.GenreId = Genre.GenreID AND Genre.Name='Pop'
GROUP BY P.PlaylistId ) AS aux)</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="asq-11" class="step pf h0 w0" data-x="29000" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the playlist(s) which contains most tracks by artist "AC/DC". <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.12 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Find the playlist(s) which contains most tracks by artist "AC/DC". <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT P.Name, COUNT(*) as count
FROM Playlist AS P, PlaylistTrack AS PL,Track,Album,Artist
WHERE P.PlaylistId = PL.PlaylistId
AND PL.TrackId = Track.TrackId
AND Album.AlbumId = Track.Albumid
AND Artist.ArtistId = Album.ArtistId
AND Artist.Name='AC/DC'
GROUP BY P.PlaylistId, P.Name
HAVING COUNT(*) = (
SELECT MAX(AUX.count)
FROM (
SELECT COUNT(*) as count
FROM Playlist AS P, PlaylistTrack AS PL,Track,Album,Artist
WHERE P.PlaylistId = PL.PlaylistId
AND PL.TrackId = Track.TrackId
AND Album.AlbumId = Track.Albumid
AND Artist.ArtistId = Album.ArtistId
AND Artist.Name='AC/DC'
GROUP BY P.PlaylistId) AS AUX)</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
<div id="asq-12" class="step pf h0 w0" data-x="29500" data-y="0" data-scale="0.4" data-timer="300" style="overflow-y: auto;">
<asq-exercise>
<asq-stem class="smaller"><h4>Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the audio tracks which have a length longer than the average length of all the audio tracks. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<asq-sqlite-q db-url="assets/Chinook_Sqlite.sqlite" font-size="0.6em">
<asq-stem class="hidden"><h4>Q.10 - Provide the SQL statement that returns the correct answers to the following query:</h4>
<h4>Return the audio tracks which have a length longer than the average length of all the audio tracks. <a href="img/ChinookDatabaseSchema1.1.png" target="_blank">Chinook Schema</a></h4>
</asq-stem>
<code></code>
<asq-solution>SELECT Track.Name
FROM Track,MediaType
WHERE Track.MediaTypeId = MediaType.MediaTypeId
AND MediaType.Name LIKE '%audio%'
AND Track.Milliseconds > (
SELECT AVG(Milliseconds)
FROM Track,MediaType
WHERE Track.MediaTypeId=MediaType.MediaTypeId
AND MediaType.Name LIKE '%audio%')</asq-solution>
</asq-sqlite-q>
</asq-exercise>
</div>
</div>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/asq-impress-js/js/impress.js"></script>
<script src="bower_components/usi-web-atelier-slides-common/js/highlight.min.js"></script>
<script src="js/main.js"></script>
<script src="bower_components/impress-step-timer/impress-step-timer.js"></script>
<script src="js/display-asq-solutions.js"></script>
</body>
</html>