skyace888 Posted October 12, 2006 Share Posted October 12, 2006 I am working on a PHP/MySQL statistics tracking program for a basketball team. It is something I'm doing for a class. I have two tables, Play_Log and Play_Outcome_Log, for which I need to run a query on. Here is what I have so far:SELECT OutcomeID, Code1 FROM Play_Outcome_Log, Play_Log WHERE Play_Outcome_Log.OutcomeID=5 AND Play_Outcome_Log.PlayID = Play_Log.PlayID AND Play_Log.PlayCode='O'I am trying to run a query that tells me the player number with the most 2-point baskets on the team (in this example). The OutcomeID represents the code of the play. "5" is for a 2-point basket. Since I want it for the main team, I choose 'O' for PlayCode meaning offensive. Here is what was returned:OutcomeID Code1 5 35 35 32I have not added all of the plays in, but at this point, player #3 is the one with the most 2-point baskets. How can I change the query so I only receive this one number as my result (the player number with the most 2-point baskets)? Hopefully I have explained this clearly.Thanks,Al Link to comment https://forums.phpfreaks.com/topic/23767-specific-query-with-two-tables/ Share on other sites More sharing options...
fenway Posted October 12, 2006 Share Posted October 12, 2006 [code]SELECT Code1, COUNT(*) AS cntFROM Play_Outcome_Log INNER JOIN Play_Log ON Play_Outcome_Log.PlayID = Play_Log.PlayID WHERE Play_Outcome_Log.OutcomeID=5 AND Play_Log.PlayCode='O'GROUP BY Code1 ORDER BY cnt DESC LIMIT 1[/code] Link to comment https://forums.phpfreaks.com/topic/23767-specific-query-with-two-tables/#findComment-108004 Share on other sites More sharing options...
skyace888 Posted October 12, 2006 Author Share Posted October 12, 2006 Thanks fenway! I think that did the trick. I know basic SQL but this one is out of my league! Link to comment https://forums.phpfreaks.com/topic/23767-specific-query-with-two-tables/#findComment-108049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.