Database Joins, Keys and Relationships

Coders’ Campus

Before we get into the show notes for this podcast episode, I want to spend some time talking about a brand new community.

I’m a BIG believer in online communities. Masterminds and communities are the main reason why I’ve come as far as I have in my life. Online communities are where I’ve met some of my closest friends and they have guided me through some very challenging parts of my career.

So it came as a bit of a shock to me that I don’t belong to an online community dedicated to programmers.

When I tried to find a community for programmers online, I just couldn’t find any good ones.

So, being the “go-getter” that I am, I’ve decided to start our very own community dedicated to programmers and the advancement of our common goal – To be a success as a programmer. I’ve named this community Coders’ Campus and it will be dedicated to helping programmers succeed in their programming journey.

Database Keys

Okay, now that I’ve talked a bit about that cool new community for programmers, it’s time to go over the show notes for this particular podcast episode.

Here’s a diagram that outlines the example relationship I was mentioning in the podcast episode. This one uses “Account” and “Address”, but you can just replace “Account” with “User” to make it work with the example I mentioned in the episode.

Here you’ll notice that the “Account” table has declared a primary key known as “Account_id”, and the “Address” table holds a relationship via the foreign key “Account_id”

This relationship is what we use to be able to JOIN data from the “Account” table to the “Address” table.

Here’s an example of how we would read data from these tables by joining them together:

This will actually join ALL the data from the “Account” table to the “Address” table… but what if we just want to get the information for a single account? Well we would just add a ‘where’ clause to our sql like so: