Multiple Tables with Reddit

*I need help with Extra Practice for the Reddit question 5.

Now let’s join the data from the different tables to find out some more information.

Use a LEFT JOIN with the users and posts tables to find out how many posts each user has made. Have the users table as the left table and order the data by the number of posts in descending order.

This is what I have so far:

SELECT users.username, COUNT(*) AS ‘posts_made’
FROM users
LEFT JOIN posts
ON users.id = posts.id
GROUP BY users.id
ORDER BY 2 DESC;

I am not getting any results

I can’t see anything immediately wrong with it. It might be worth editing out sections of this query to find out what does run for some basic debugging (e.g. use -- on various lines until it does run). I’m not sure but the id column could be an issue (which id is associated with which table?). I’d also suggest double-checking it’s not another query that’s causing problems (even a missing ; could block all other results in the workspace).

posts.id in the 4th line should be posts.users_id

Hey all,

I’m dong the same extra practice and keep getting no results, what I am I doing wrong? this is what I have. Is it the users.id as ON? I’m at loss

SELECT users.username, COUNT(*) AS ‘posts_made’
FROM users
LEFT JOIN posts
ON users.id = posts.users_id
GROUP BY users.id
ORDER BY 2 DESC;

Hello @cvondran ,

Your query looks correct. Try re-running the query again.

1 Like

Thank you!

still not returning results, I’ve submitted feed back

Hi @cvondran ,

Sorry I missed this earlier.

-- It should be posts.user_id NOT posts.users_id
ON users.id = posts.user_id
1 Like

that would make sense why it wouldn’t run.

thank you so much!

1 Like