The basic explanation is that the where part of the query 'fires' before the group by, and the having fires after, on the grouped data.
Also, you should avoid constructs like:
select u.*, count(field1) from table group by field1
since technically, there may be more than one u.* field for each row, and which one you're getting is not defined. I.e.:
table1:
id | num
1 | 1
1 | 2
1 | 1
1 | 3
2 | 1
2 | 2
2 | 4
select id, num from table1 group by id;
which num should be returned? 1, 2, 1, or 3 for id 1, or 3 1 2 or 4 for id 2? The correct way to do this (and a way that will work if you hit a database other than MySQL) is to use max/min:
select id, max(num) from table1 group by id;