schone Posted May 10, 2006 Share Posted May 10, 2006 HiJust a summary about my tables:[b]players_answers[/b]- id (auto_inc)- date- player_id- value[b]players[/b]- id (auto_inc)- player_id- givenname- surnameHere is my query:[code]SELECT players_answers.player_id, players_answers.date, players.player_id, players.givenname, players.surnameFROM players_answers INNER JOIN players ON (players_answers.player_id = players.player_id AND date=NOW()) GROUP BY players_answers.player_id[/code]What i'm trying to do is grab all the players names that have an entry on today's date. [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]Which works fine![!--colorc--][/span][!--/colorc--][b]My problem is[/b] that how would I go about getting all the players name's that don't have an entry on this date. So the exact opposite of this query!I have tried to use date!=NOW(). But the problem is all players in the players_answers have dates ranging back to Janurary, so all players get displayed when I put that clause in.[b]Please someone help![/b]Thank You! Quote Link to comment Share on other sites More sharing options...
fenway Posted May 10, 2006 Share Posted May 10, 2006 Try the following (UNTESTED):[code]SELECT players_answers.player_id, players_answers.date, players.player_id, players.givenname, players.surnameFROM players LEFT JOIN players_answers ON (players_answers.player_id = players.player_id AND date=NOW()) WHERE players_answers.player_id IS NULL[/code]BTW, you shouldn't have the group by in either of these. Quote Link to comment Share on other sites More sharing options...
schone Posted May 13, 2006 Author Share Posted May 13, 2006 [!--quoteo(post=372954:date=May 10 2006, 10:59 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 10 2006, 10:59 AM) [snapback]372954[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try the following (UNTESTED):[code]SELECT players_answers.player_id, players_answers.date, players.player_id, players.givenname, players.surnameFROM players LEFT JOIN players_answers ON (players_answers.player_id = players.player_id AND date=NOW()) WHERE players_answers.player_id IS NULL[/code]BTW, you shouldn't have the group by in either of these.[/quote]Hi Fenway!The following query displays every player_id. :( I have asked every person I know that knows mySql about this and no one can work it out! Quote Link to comment Share on other sites More sharing options...
shoz Posted May 13, 2006 Share Posted May 13, 2006 [quote][quote]Try the following (UNTESTED):[code]SELECT players_answers.player_id, players_answers.date, players.player_id, players.givenname, players.surnameFROM playersLEFT JOIN players_answers ON (players_answers.player_id = players.player_id AND date=NOW())WHERE players_answers.player_id IS NULL[/code]BTW, you shouldn't have the group by in either of these.[/quote]Hi Fenway!The following query displays every player_id. :(I have asked every person I know that knows mySql about this and no one can work it out![/quote]From the way you've described your tables, as far as I can see fenway's query should have worked. I have tested it on sample data and get the desired results. Perhaps you should post the script you're currently using to retrieve the players. You may have forgotten something.The following should also work, but I'd assume the JOIN would be faster.[code]SELECTplayer_id, givenname, surnameFROMplayersWHERE player_idNOT IN ( SELECT players.player_id FROM players_answers INNER JOIN players ON (players_answers.player_id = players.player_id AND date=NOW()) )[/code] 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.