Hi, I’m doing the exercise “Identifying the most popular book in the catalogue”, I actually arrived to the same answers, altough with a little different query, I want to know if my result as pure lucky or is just another way to solve it. My query was:
SELECT
name,
COUNT(user_id) AS number_users
FROM books_users bu
INNER JOIN books b
ON bu.book_id = b.id
GROUP BY 1
ORDER BY 2 DESC, 1 ASC
An the solution was the following:
SELECT
name,
COUNT(DISTINCT(bu.user_id))
FROM books_users bu
INNER JOIN books b
ON bu.book_id = b.id
GROUP BY 1
ORDER BY 2 DESC, name ASC
Also, I want to know what’s the “general rule” to do inner joins, is there a difference which table I use first and which I join?
Thanks!!