mysql COUNT results with GROUP BY

ID : 274475

viewed : 51

Tags : mysqlmysql





Top 3 Answer for mysql COUNT results with GROUP BY

vote vote

92

Your requirement is to get count of number of groups. So we need two operations-

  1. Group(inner query)
  2. Count(outer query)

Following query will do precisely that:

SELECT COUNT(*) FROM (     SELECT COUNT(id)      FROM my_table      GROUP BY first_linked_table_id,              second_linked_table_id ) t 
vote vote

87

If you want to count the rows, I think you're going to need a subquery. Something like this:

SELECT COUNT(*) FROM (     SELECT COUNT(id) FROM my_table GROUP BY first_linked_table_id, second_linked_table_id ); 
vote vote

74

Top 3 video Explaining mysql COUNT results with GROUP BY







Related QUESTION?