akphidelt2007 Posted March 21, 2016 Share Posted March 21, 2016 Alright, I've been doing this for too long to not understand what is going wrong here. This is pretty straightforward. I have one table with the columns... ID | Year | Away_Team | Home_Team -1---2010-----tacoma--------puyallup -2---2010-----puyallup-------renton -3---2010-----renton---------tacoma -4---2010-----puyallup-------tacoma What I want is just a simple count of the total # of games played by year and team regardless of it being an away or home game. Year | Team | Games -2010--tacoma---3 -2010--renton----2 Any help will be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/301061-group-by-year-name-and-count-from-two-fields-on-same-row/ Share on other sites More sharing options...
Solution Barand Posted March 21, 2016 Solution Share Posted March 21, 2016 (edited) You need to use a UNION SELECT Year , Team , COUNT(*) as Played FROM ( SELECT Year, Away_Team as Team FROM table UNION SELECT Year, Home_Team as Team FROM table ) teams GROUP BY Year, Team Edited March 21, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/301061-group-by-year-name-and-count-from-two-fields-on-same-row/#findComment-1532303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.