Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-03-2007, 07:30 PM   PM User | #1
alex57
Regular Coder

 
Join Date: Sep 2006
Posts: 216
Thanks: 9
Thanked 0 Times in 0 Posts
alex57 has a little shameless behaviour in the past
Comparing two table to find what doesnt exist

I have two tables:

Code:
CREATE TABLE `FootballerScore` (
  `footballerID` mediumint(4) NOT NULL default '0',
  `GameWeekID` mediumint(4) NOT NULL default '0',
  `GameRuleID` mediumint(4) NOT NULL default '0',
  `Goals` mediumint(4) NOT NULL default '0',
  `Assists` mediumint(4) NOT NULL default '0',
  `CleanSheets` mediumint(4) NOT NULL default '0',
  `YellCards` mediumint(4) NOT NULL default '0',
  `RedCards` mediumint(4) NOT NULL default '0',
  `WeeklyScore` mediumint(4) NOT NULL default '0',
  `AccScore` mediumint(6) NOT NULL default '0',
  PRIMARY KEY  (`footballerID`,`GameWeekID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `footballers` (
  `footballerID` mediumint(15) NOT NULL default '0',
  `fname` varchar(15) collate latin1_general_ci NOT NULL default '',
  `sname` varchar(15) collate latin1_general_ci NOT NULL default '',
  `value` decimal(15,1) NOT NULL default '0.0',
  `PremTeamID` mediumint(15) NOT NULL default '0',
  `position` varchar(15) collate latin1_general_ci NOT NULL default '',
  `Importance` varchar(4) collate latin1_general_ci NOT NULL default '',
  PRIMARY KEY  (`footballerID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
The footballers table basically has a list of all the players in the premiership and the footballerscore table has a list of the player who played in a given week. For any one week I need to find out who DIDNT play. I can do this by comparing all the footballerIDs in both tables and the difference is the group I need. However I'm not sure how to put this into an SQL statement . Any ideas??

thanks in advance
alex57 is offline   Reply With Quote
Old 03-03-2007, 09:24 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
If all the footballers who play this week show up in the footballerscore table, and the week can be designated as x for perhaps 13 or week 13 or '2007-03-03' then you can get those not playing from:

Code:
select 
footballers.footballerID
from footballers
where footballers.footballerID 
NOT IN
(select footballerscore.footballerid
from footballerscore
where gameweekid = x)
GO READING FC!
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:49 AM.


Advertisement
Log in to turn off these ads.