Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking on names rather than ids #10

Closed
ZooeyMiller opened this issue Mar 29, 2017 · 3 comments
Closed

Linking on names rather than ids #10

ZooeyMiller opened this issue Mar 29, 2017 · 3 comments

Comments

@ZooeyMiller
Copy link

ZooeyMiller commented Mar 29, 2017

in the seconds exercise you have to link the tables together like this:

SELECT mentors.name, count (post_num) FROM mentors
INNER JOIN posts
ON mentors.name = posts.mentor_name
INNER JOIN likes
ON posts.num = likes.post_num
GROUP BY mentors.name;

We are joining on names, and then on post_num.
Yesterday in our research we were led to believe that we should INNER JOIN on the IDs, not the names as those things can be variable, and joining on ID is then a consistent way for our databases to work.

I just wanted to raise an issue because I found it a bit confusing to join in a way I had been led to believe was bad practice.
(I may even have a wrong solution! Sorry if I'm wrong, just confused).

@ZooeyMiller
Copy link
Author

Someone else just casted and showed this solution:

SELECT posts.mentor_name, COUNT(likes.post_num) 
FROM likes INNER JOIN posts
ON likes.post_num = posts.num
GROUP BY posts.mentor_name

Which shows you don't need to link on name, but you do still link on "num" rather than "id" which I still find a wee bit confusing.

@shiryz
Copy link
Member

shiryz commented Mar 29, 2017

@ZooeyMiller , you're right about it being good practice to put an id in the table as a primary key, but you can still join by any column you'd like and it doesn't have to be the id.

@shiryz
Copy link
Member

shiryz commented Jun 19, 2019

Closing, this is now outdated

@shiryz shiryz closed this as completed Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants