OK so we've established that in real life data can be crazy complex outside the classroom.
Things aren't as nice as we'd like them to be.
So we've established that fact but now where do we start to kind of wrap her head around how we represent
complex data using my queue up.
And the answer is we're going to start talking about the relationship basics.
So I know it sounds like you know marriage counseling 101 or something but this is not that it's not
that this is about the different ways that data can be related.
So if we have two tables or two entities things like mortars and customers and students and teachers
movies and reviews and users how how are they related.
And there's a couple of different ways there's that kind of these big broad categories we can break
relationships down into and the terms that I'm going to use that you'll occasionally come across are
three.
There's a first one which is a one to one relationship and it's going to go through all of them first
before we talk about what they mean.
And you talk about examples.
So one to one relationship a one to many relationship and then a many to many relationship.
So the reality is that one to one relationships aren't actually that common but perhaps another example
or one that I've recently used is had a Customers table that had the basic information for a customer.
So things like the username and password although again you don't actually store the password directly
but your name and password and email and the registration date.
And then there was a separate table where we stored all these details about our customer.
So rather than storing 10 or 20 extra columns on the basic customer table we decided to split it up
based off of what was most commonly needed in the app we were building.
And most commonly All we needed was a user name and the password and the email but there was a whole
bunch of other information that we were storing.
So we created a customer details table.
And that's a one to one relationship.
One customer has their own row one row in the customer details table and one customer details row is
associated with one customer.
So cold still has a cold steel customer details but there is no other user or customer that could be
associated with it because it's a one to one relationship anyway so I guess that is not the most common
what is the most common is actually a one to many relationship and that's what we'll spend the most
time on in this course because like I said it's really common.
So here's an example the relationship between books and reviews.
One book can have thousands of reviews right.
Let's say into thin air by Jon Krakauer could have probably tens of thousands of reviews by this point.
Been out for a while.
It's pretty popular but those reviews belong to that book exclusively to one book.
So the relationship is books have many reviews but reviews belong to one book so it's a one to many.
So that's a really common classic example.
Reviews are ratings and books are some entity.
OK.
So then the next thing that we'll discuss here is a many to many relationship and many to many is still
relatively common in the way that it works.
So what it sounds like we have two entities in this case books and authors and you kind of speak through
it.
You could say OK books can have many authors.
That's true.
We could have two authors writing a book together and those authors can have many books.
There's no rule that says authors get know can only write one book.
You know J.K. Rowling rambling However you say that as ten plus books so it's a two way many to many
relationship.
So hopefully you can see the difference to their reviews in books reviews belong to one book.
They're associated only with one book whatever the book title is for that review.
It can also be the same review associated for another book.
So that part of the relationship is one.
Right.
And then we have the books to reviews which is a many relationship books have many reviews.
This is different because books can have multiple authors and authors can be long to multiple books
or authors can have multiple books.
And the way that we represent this is actually a little more complex.
So we're going to come back to it.
We're going to start off in this section by talking about the most common relationship and how we represent
that which is the one to many relationship.
So that's coming up next.