ghgarcia Posted August 12, 2006 Share Posted August 12, 2006 I have two tables that I need to query and get counts. The table structure follows:Schedule Tablegameid int(11) Noweek int(5) Nogametime int(16) Novid varchar(5) Novscore int(5) Nohid varchar(5) Nohscore int(5) Noot enum('Y','N') Noresult varchar(5) Nospread float(5,1) Nosresults varchar(5) NoPicks tableuser varchar(30) Nogameid int(3) Nopick varchar(5) NoThe gameid from both tables are the sameThe pick field from the picks table can equal either the vid or hid of the schedule tableWhat I'm attempting to do is create a query that will return the total number of picks for both hid and vid. Currently I can get only one total but not both. I'm using the following query:select s.hid, count(p.pick) as total, s.week from lvb_picks as p, lvb_schedule as s where p.gameid = s.gameid and s.hid = p.pick or s.result group by s.hid order by total desc;Any help would be greatly appreciated.George Quote Link to comment Share on other sites More sharing options...
bigmatt19 Posted August 12, 2006 Share Posted August 12, 2006 not sure exactly what you're looking for... but something like this might help:SELECT (SELECT count(*) FROM scheduleTable WHERE [i]args here for [b]hid[/b][/i]) AS hidTotal, (SELECT count(*) FROM scheduleTable WHERE [i]args here for [b]vid[/b][/i]) AS vidTotal [i]everything else you want to grab[/i];Or if you want to add them then this might work:SELECT ((SELECT count(*) blah blah) + (SELECT count(*) blah blah)) AS total, [i]everything else[/i]Then again you might want to look in the MySQL manual about "OUTER JOIN" (LEFT JOIN, etc.) It could possibly yield some quicker queries, though the ones I posted should work just fine.Hope that helps..-matt Quote Link to comment Share on other sites More sharing options...
ghgarcia Posted August 12, 2006 Author Share Posted August 12, 2006 I'm a novice in MySql queries. Let me explain a little more I have a football pool which contains several tables i.e. the schedule table and picks table.The schedule table contains information about the games for the season it contains hid (the id of the home team), vid (the id of the visiting team) and the date/time of the game it also contains a score once the game has finished.The picks table contains information about user picks for a game it contains gameid which points to the schedule gameid then it contains the pick which is equal to the vid or hid from the schedule table. There is a entry for each game that the user selected to win.So what I need is a query that would show total number of picks (from the picks table) for home team (hid) and visiting team (vid) for each game.the returned table could look like:gameid vid hid1 4 32 2 5I have a test site with a query function that connects to my database at [url=http://lvbash.com/phpfootball/mysql_send.php]http://lvbash.com/phpfootball/mysql_send.php[/url] If you'd like to test.Thanks again for your help I really appreciate it.George Quote Link to comment 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.