Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Now that we understand a little bit about what Relational Databases are and why we structure them the way we do, let’s take a higherlevel look at how to think about data.
Set Theory was founded in 1874, and is a relatively new mathematical discipline, as compared to Algebra or Calculus.
For more history and info about the topic, check out the Wikipedia page on Set Theory
This link takes a look at Set Operations in SQL, but we’ll be covering this more in a later stage.

0:00
Now that we understand a little bit about what relational databases are and

0:04
why we structure them in the way that we do.

0:07
Let's take a high level look at how to think about data.

0:11
You can think of a database table as a set of data stored to a disk.

0:15
You can add and remove dates to the set and you can update it.

0:20
When you query a table you get the whole set or even a subset of data back.

0:26
This is known as a result set.

0:29
You may have notice me saying the word settle up.

0:31
A set means a grouping of similar things and

0:34
they are the foundation of performing useful queries in relational databases.

0:39
Let's take a look at a few examples of some simple sets.

0:44
Remember, a set means a grouping of similar things together.

0:48
You could have a set of things you can wear.

0:50
Shirts, shoes, socks, coats, or you could have a more specific set of shirts.

0:56
Tshirt, dressshirts, sweaters.

1:00
Items like shoes and socks belong in the first set but not the second set.

1:05
You can wear socks and shoes but they aren't types of a shirt.

1:09
Or you could have a set of fruits, apples, bananas, strawberries, pears.

1:14
Or sets of apples, granny smith, fugue, red delicious.

1:18
In this example, the definition of the second set, apples,

1:22
excludes items from the more inclusive set of all fruits.

1:28
You can also depicts sets conceptually as graphs called the Venn diagrams.

1:33
These graphs help us show whereas one set might overlap with another or

1:37
why one set is distinct from other sets.

1:41
Let's say we have a group of people who like certain types of fruits and

1:45
we want to show who likes what.

1:48
We can depict this with Venn diagrams.

1:51
Here we have two small sets.

1:53
The sets of people who like apples and the sets of people who like bananas.

1:58
The people who like apples are John, Stacy, Indira and Bob.

2:05
And the people who like bananas are Indira, Bob and Dante.

2:10
Now let's look at a common element for both sets.

2:14
In this case, the elements are people.

2:17
As we overlay the two sets you can see that both Bob and

2:22
Indira are the two people who like both apples and bananas.

2:26
This area in the middle is called the intersection between two sets.

2:31
The entirety of both circles combined,

2:34
in this case all people who like apples or bananas, is called the union.

2:41
Finally, what if we want to just find the people who like one fruit or

2:46
the other but not both.

2:48
This is called an except, all people who like apples, and

2:52
all people who like bananas except the people who like both.

2:58
When we perform an intersection, union or

3:01
except on sets of data, these are known as set operations.

3:06
Remember, tables and the results from queries a called data sets.

3:10
When you write a query for a port or

3:12
dynamic application, you're actually working with datasets.

3:17
That can have set operations performed on them.

3:20
Remember that a set is a collection of similar things, a data set

3:25
is nothing more than a collection of rows with the same column definitions.

3:30
A table is a data set that is stored physically on a disk.

3:35
Let's take a look at our Venn diagram example again, but

3:38
this time let's use data.

3:41
Here we see two small tables, our group of people who like apples is in

3:46
one table and then the group of the other people who like bananas in another.

3:52
Let's analyze that data for the people who like both apples and bananas.

3:57
This is the intersection from our Venn diagram a minute ago.

4:01
Now, let's see all people regardless of which fruit they like.

4:06
This is the union from our Venn diagram.

4:08
And now let's look for just people that like one fruit or the other, but not both.

4:14
This is the except example from a minute ago.

4:17
This normalization process helps databases perform set operations of intersection,

4:23
union, and except in fast and efficient ways.

4:27
As we get deeper into this course, we'll study this in more detail.

4:31
Keep the image of a Venn diagram in your mind to help you visualize the concepts.
You need to sign up for Treehouse in order to download course files.
Sign up