If COUNT
is all you want, you can do it with a subquery rather than a join, like this:
SELECT u.*
, (SELECT COUNT(*) FROM notes WHERE notes.user_id=u.id) as amountnotes
FROM users u
ORDER BY amountnotes DESC
If you do it the JOIN
way, your GROUP BY
should list all columns of the user
(although MySql is one of the RDBMS systems that does not require this, porting such SQL to databases of other vendors becomes problematic).