31.07.2016, 08:51
You'll want to use "group by". Bascially what you want to do is this:
That will then produce a list of factionids and the number of rows for each. To add the name you need to join the other table. I'm not sure if the query below is entirely correct because I don't have a database to test it with.
PHP код:
SELECT factionid, COUNT(factionid) AS memberCount FROM Accounts GROUP BY factionid
PHP код:
SELECT a.factionid, f.Name, COUNT(a.factionid) AS memberCount FROM Accounts a INNER JOIN Faction f ON f.ID = a.factionid GROUP BY a.factionid, f.Name