I have a database with two tables. One called 'Combatants' with a column 'combatantID'. Another called 'Kills' with columns 'killID', 'shooter' and 'victim'. Both shooter and victim are foreign keys pointing to `Combatants.combatantID'. I would like to make a query that will return data in a table with the form:
combatantID,kills,deaths
I can get it working for either kills or deaths but not both. To do one or the other I've been using this query:
SELECT Combatants.combatantID, COUNT(K1.killID) as kills
FROM Combatants
INNER JOIN Kills as K1 ON K1.shooter=Combatants.combatantID
GROUP BY Combatants.combatantID
However if I put another INNER JOIN with table Kills as K2 and add COUNT(K2.killID) as deaths I get an odd result that I think is the sum of all player kills, all player deaths instead of player specific kills, deaths.
Any advice would be greatly appreciated. Thanks in advance.
grouprelated operation... and try left joins for don't change result rows number