≡ Menu

Database Joins, Keys and Relationships

cc_square

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.

Benefits of Joining Coders’ Campus

  • Help with assignments and exams from your community through HipChat, Google hangouts and email
  • Video walkthroughs of homework assignments from experts
  • Access to a constantly updated list of interview questions and answers
  • Recurring Google hangouts where you can meet and greet your new friends in the community, network and share your knowledge
  • Mock interviews to ensure you NAIL your next programming interview
  • Help with solving those annoying bugs in your program and more!

Join Coders’ Campus



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.

Account - Address Relationship

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:

select * from Account
inner join Address on Account.account_id = Address.account_id;

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:

select * from Account
inner join Address on Account.account_id = Address.account_id
where Account.firstname = 'trevor'
and Account.lastname = 'page';

{ 0 comments… add one }

Leave a Comment

Powered by sweet Captcha