Since all the users in the premium users table are premium users, shouldn’t there be a special “join” we can use to only show these? so we wouldn’t need the “where” condition? like an inner join for example?
I just tried it and it worked, as in has the same count of user ids as the initial answer: 100.
this is my code:
SELECT COUNT(id)
from users
INNER JOIN premium_users
ON users.id = premium_users.user_id;
haha, nevermind, I thought we only wanted premium users but instead we want the free users
but if we only wanted premium users we could do an inner join…
Kind of feel this code challenge is too hand-holding, would be more challenging (and would cement previously taught topics) if there was less guides on how to bring up prompted question. What I mean by hand holding:
" Use a LEFT JOIN to combine users and premium_users and select id from users .
The column id in users should match the column user_id in premium_users .
Use a WHERE clause to limit the results to users where premium_users.user_id IS NULL . This will remove premium users and leave you with only free users."
I would also love a clarification on how the solution code matches IS NULL.
Solution Code:
SELECT users.id
FROM users
LEFT JOIN premium_users
ON users.id = premium_users.user_id
WHERE premium_users.user_id IS NULL;
Thanks in advance!
P.S. Just like other learners mention in this particular thread, there is to much information in the instructions. A more realistic scenario would be that we get a visual representation of what is expected, then we should try to produce it.
I believe after left join is performed it will create empty cells in the query result (premium_users.user_id) .
You could use this code to visualize this.
SELECT *
FROM users
LEFT JOIN premium_users
ON users.id = premium_users.user_id
LIMIT 10;
The main problem i find with the way join concepts are taught here is lack of explanation of exact logic behind different kind of joints. I always have to google for more visual examples to grasp these concepts.
Hi together,
I would like to understand why this doesn’t yield any results, whereas a pure count (not a distinct out) actually works out and gives 100 as a result?