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... Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/ 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) Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864431 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); Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864432 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` Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864433 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.. Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864442 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` Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864460 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. Link to comment https://forums.phpfreaks.com/topic/163829-solved-get-total-of-rows/#findComment-864542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.