MySQL: Problems counting rows
Is this supposed to count the appearances of each link_id on the table?
SELECT link_id, count(*) FROM table group by link_id
I think it should, but if I just execute
SELECT * FROM table
I get different 开发者_开发百科results. For example, for link 7 I get a count of 40 in the first query, but using 'select *' i see that there are only 4 rows of link 7... What's going on?
Yes it is supposed to do that,
Surely it would be easier to do a
SELECT DISTINCT count(link_id) FROM table
This would give you a single row containing the amount of link_id's
Alternatively
SELECT link_id,count(*) FROM table GROUP BY link_id's
Returns multiple rows containing the count of each
With regard to the original question you mention there are multiple rows per id, are you doing a join any where?
I get different results. For example, for link 7 I get a count of 40 in the first query, but using 'select *' i see that there are only 4 rows of link 7... What's going on?
Are you sure phpMyAdmin or similar isn't limiting the amount of rows you are seeing?
精彩评论