[eluser]vitoco[/eluser]
Code:
$sql = "
SELECT
id_student ,
COUNT( id_class ) AS number_of_classes
FROM
table
GROUP BY
id_student
HAVING
number_of_classes > 1
";
How this work?, "GROUP BY $field" gives one row per $field and do the operations ( on select ) to the other fields, SUM(), COUNT(), GROUP_CONCAT(), etc...in this case, count the "id_class" per id_student
!! Note that "number_of_classes" can't be conditioned on WHERE, cause it's not a "original" field, and it can be condiotioned on "HAVING"., on this particular case, will limit ( return ) only the students with more than 1 class
Slds.