What I think you want to do is use a GROUP BY on the RuleId field, specifying a RuleId='x,y, or z', along with a call to the COUNT() function in your query.
Try:
SELECT *,COUNT(*) FROM `minirules_minmax` where RuleId = '" & contractId & "'" GROUP BY RuleId;
You can also do things with SUM() and MAX() in this type of query, as well. For instance, on the User table in the mysql database:
mysql> SELECT Insert_priv,SUM(IF(host!='localhost',1,0)) FROM `user` where user!= 'root' GROUP BY Insert_priv;
+-------------+--------------------------------+
| Insert_priv | SUM(IF(host!='localhost',1,0)) |
+-------------+--------------------------------+
| N | 1 |
| Y | 4 |
+-------------+--------------------------------+
Immediately, you see four remote users of your DB with insert privileges, and 1 (probably user='') with none.
|