Similar to this question here MySQL: Count occurrences of distinct values
However I'd like to return each individual occurrence of the row, with the count for the name. i.e.
expected result:
id name count
----- ------ ------
1 Mark 2
2 Mike 3
3 Paul 1
4 Mike 3
5 Mike 3
6 John 1
7 Mark 2
I can achieve this with a subquery, but my particular example has a complicated main query to filter the results down, and I'd like to avoid having to duplicate that query to achieve correct counts.