Counting GROUP BY Data in PHP

Asked By 20 points N/A Posted on -
qa-featured

I’ve been using GROUP BY in my query but I can’t count the data being grouped. Can anyone help me on how to count the number of grouped data? Thanks. 

 

SHARE
Answered By 40 points N/A #102888

Counting GROUP BY Data in PHP

qa-featured

 

Hello there Kenny,

Group By in SQL is not the solution to what you want to achieve. Group by function of SQL only groups your data according to the specified field you have chosen. If you want to achieve what you want, use the COUNT function of SQL. It lets you count the number of the selected field you have grouped by. To illustrate this, take a look with the code below.

SELECT au_id, COUNT(*) as “num_books”  from title_authors  GROUP BY au_id;

If you want to learn more with SQL you can come to this site:

 

Hope this helps you,

Regards Roland. 

Login/Register to Answer

Related Questions