zeeshan_haider000 Posted June 27, 2009 Share Posted June 27, 2009 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... Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 27, 2009 Share Posted June 27, 2009 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) Quote Link to comment Share on other sites More sharing options...
AwptiK Posted June 27, 2009 Share Posted June 27, 2009 $sql = "SELECT * FROM table WHERE group = 'a'"; $resulta = mysql_query($sql,$con); $rowsa = mysql_num_rows($resulta); $sql= "SELECT * FROM table WHERE group = 'b'"; $resultb = mysql_query($sql,$con); $rowsb = mysql_num_rows($resultb); Quote Link to comment Share on other sites More sharing options...
Philip Posted June 27, 2009 Share Posted June 27, 2009 Or using one query: SELECT COUNT(*) FROM `table` GROUP BY `group` Quote Link to comment Share on other sites More sharing options...
zeeshan_haider000 Posted June 27, 2009 Author Share Posted June 27, 2009 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.. Quote Link to comment Share on other sites More sharing options...
trq Posted June 27, 2009 Share Posted June 27, 2009 SELECT COUNT(`group`) FROM `table` GROUP BY `group` Quote Link to comment Share on other sites More sharing options...
zeeshan_haider000 Posted June 27, 2009 Author Share Posted June 27, 2009 SELECT COUNT(`group`) FROM `table` GROUP BY `group` Thank you, it worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.