Jump to content

[SOLVED] Get total # of rows...


Recommended Posts

Hi,

My table looks something like this:

 

table1:

Name : abc

Id: 1

Group: a

Num: 1

---------------

table1:

Name : sds

Id: 3

Group: a

Num: 2

--------------

Name: bbc

Id: 2

Group: b

Num: 5

--------------

 

I am trying to get total number of rows that are in Group "a" and group "b". For example in group "a" there are 2 peoples and in group "b", 1 person. So how would you achieve this using a query? Inner join etc?

 

Regards...

Link to comment
https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/
Share on other sites

Hi,

My table looks something like this:

 

table1:

Name : abc

Id: 1

Group: a

Num: 1

---------------

table1:

Name : sds

Id: 3

Group: a

Num: 2

--------------

Name: bbc

Id: 2

Group: b

Num: 5

--------------

 

I am trying to get total number of rows that are in Group "a" and group "b". For example in group "a" there are 2 peoples and in group "b", 1 person. So how would you achieve this using a query? Inner join etc?

 

Regards...

 


SELECT * FROM table WHERE group = 'a';

$rowsa = myql_num_rows($results)

SELECT * FROM table WHERE group = 'b';

4rowsb = mysql_num_rows($results1)

Or using one query:

SELECT COUNT(*) FROM `table` GROUP BY `group`

 

Sorry if i wasn't clear, the group can be anything, that was just an example. I want a query like ex:

Count Number of Fields that are under the group 'group' (anything can be in this 'group' field)

Say in my table i have 20 different groups and there are 100 people in these groups, i wnat to know how many ppl are in each group. I want to accomplish this using one query only.

Regards..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.