1 00:00:00,420 --> 00:00:04,470 Now that we understand a little bit about what relational databases are and 2 00:00:04,470 --> 00:00:07,140 why we structure them in the way that we do. 3 00:00:07,140 --> 00:00:10,240 Let's take a high level look at how to think about data. 4 00:00:11,270 --> 00:00:15,960 You can think of a database table as a set of data stored to a disk. 5 00:00:15,960 --> 00:00:20,050 You can add and remove dates to the set and you can update it. 6 00:00:20,050 --> 00:00:26,060 When you query a table you get the whole set or even a subset of data back. 7 00:00:26,060 --> 00:00:27,950 This is known as a result set. 8 00:00:29,090 --> 00:00:31,530 You may have notice me saying the word settle up. 9 00:00:31,530 --> 00:00:34,470 A set means a grouping of similar things and 10 00:00:34,470 --> 00:00:39,940 they are the foundation of performing useful queries in relational databases. 11 00:00:39,940 --> 00:00:44,340 Let's take a look at a few examples of some simple sets. 12 00:00:44,340 --> 00:00:48,310 Remember, a set means a grouping of similar things together. 13 00:00:48,310 --> 00:00:50,031 You could have a set of things you can wear. 14 00:00:50,031 --> 00:00:56,548 Shirts, shoes, socks, coats, or you could have a more specific set of shirts. 15 00:00:56,548 --> 00:01:00,280 T-shirt, dress-shirts, sweaters. 16 00:01:00,280 --> 00:01:05,370 Items like shoes and socks belong in the first set but not the second set. 17 00:01:05,370 --> 00:01:09,470 You can wear socks and shoes but they aren't types of a shirt. 18 00:01:09,470 --> 00:01:14,550 Or you could have a set of fruits, apples, bananas, strawberries, pears. 19 00:01:14,550 --> 00:01:18,490 Or sets of apples, granny smith, fugue, red delicious. 20 00:01:18,490 --> 00:01:22,930 In this example, the definition of the second set, apples, 21 00:01:22,930 --> 00:01:28,150 excludes items from the more inclusive set of all fruits. 22 00:01:28,150 --> 00:01:33,300 You can also depicts sets conceptually as graphs called the Venn diagrams. 23 00:01:33,300 --> 00:01:37,490 These graphs help us show whereas one set might overlap with another or 24 00:01:37,490 --> 00:01:40,490 why one set is distinct from other sets. 25 00:01:41,630 --> 00:01:45,870 Let's say we have a group of people who like certain types of fruits and 26 00:01:45,870 --> 00:01:48,010 we want to show who likes what. 27 00:01:48,010 --> 00:01:51,160 We can depict this with Venn diagrams. 28 00:01:51,160 --> 00:01:53,560 Here we have two small sets. 29 00:01:53,560 --> 00:01:58,560 The sets of people who like apples and the sets of people who like bananas. 30 00:01:58,560 --> 00:02:05,010 The people who like apples are John, Stacy, Indira and Bob. 31 00:02:05,010 --> 00:02:10,620 And the people who like bananas are Indira, Bob and Dante. 32 00:02:10,620 --> 00:02:14,630 Now let's look at a common element for both sets. 33 00:02:14,630 --> 00:02:17,690 In this case, the elements are people. 34 00:02:17,690 --> 00:02:22,100 As we overlay the two sets you can see that both Bob and 35 00:02:22,100 --> 00:02:26,580 Indira are the two people who like both apples and bananas. 36 00:02:26,580 --> 00:02:31,430 This area in the middle is called the intersection between two sets. 37 00:02:31,430 --> 00:02:34,750 The entirety of both circles combined, 38 00:02:34,750 --> 00:02:41,150 in this case all people who like apples or bananas, is called the union. 39 00:02:41,150 --> 00:02:46,380 Finally, what if we want to just find the people who like one fruit or 40 00:02:46,380 --> 00:02:48,340 the other but not both. 41 00:02:48,340 --> 00:02:52,950 This is called an except, all people who like apples, and 42 00:02:52,950 --> 00:02:58,340 all people who like bananas except the people who like both. 43 00:02:58,340 --> 00:03:01,000 When we perform an intersection, union or 44 00:03:01,000 --> 00:03:06,050 except on sets of data, these are known as set operations. 45 00:03:06,050 --> 00:03:10,530 Remember, tables and the results from queries a called data sets. 46 00:03:10,530 --> 00:03:12,760 When you write a query for a port or 47 00:03:12,760 --> 00:03:17,140 dynamic application, you're actually working with datasets. 48 00:03:17,140 --> 00:03:19,480 That can have set operations performed on them. 49 00:03:20,560 --> 00:03:25,330 Remember that a set is a collection of similar things, a data set 50 00:03:25,330 --> 00:03:30,660 is nothing more than a collection of rows with the same column definitions. 51 00:03:30,660 --> 00:03:34,315 A table is a data set that is stored physically on a disk. 52 00:03:35,370 --> 00:03:38,800 Let's take a look at our Venn diagram example again, but 53 00:03:38,800 --> 00:03:41,700 this time let's use data. 54 00:03:41,700 --> 00:03:46,740 Here we see two small tables, our group of people who like apples is in 55 00:03:46,740 --> 00:03:52,570 one table and then the group of the other people who like bananas in another. 56 00:03:52,570 --> 00:03:57,550 Let's analyze that data for the people who like both apples and bananas. 57 00:03:57,550 --> 00:04:01,680 This is the intersection from our Venn diagram a minute ago. 58 00:04:01,680 --> 00:04:06,130 Now, let's see all people regardless of which fruit they like. 59 00:04:06,130 --> 00:04:08,910 This is the union from our Venn diagram. 60 00:04:08,910 --> 00:04:14,715 And now let's look for just people that like one fruit or the other, but not both. 61 00:04:14,715 --> 00:04:17,965 This is the except example from a minute ago. 62 00:04:17,965 --> 00:04:23,405 This normalization process helps databases perform set operations of intersection, 63 00:04:23,405 --> 00:04:27,975 union, and except in fast and efficient ways. 64 00:04:27,975 --> 00:04:31,995 As we get deeper into this course, we'll study this in more detail. 65 00:04:31,995 --> 00:04:36,385 Keep the image of a Venn diagram in your mind to help you visualize the concepts.