Jump to content

Show result from one table where ID's match on another?


Go to solution Solved by Barand,

Recommended Posts

Evening you clever lot on here!

 

I'm sure this won't take long for you guys to give me some sterling advice!

 

I have 2 tables, 1 which has matchday results on it, 1 which has player details on it. The ID's match up and tie in in the database, but on the page i'm on, I would like to display all the players that haven't got a value for this specific matchday. Important table layouts as follow:

 

MatchdayScore

 

PlayerID, MatchNumber

1234, 12

 

Players

 

PlayerID, PlayerName

1234, Player One

 

Each time a player plays a game, MatchNumber will have the relevant match number added for that player, so as you can see above, Player One (1234) has taken part in MatchNumber 12. I would like to add a search if possible to say something like:

 

Select * FROM Players WHERE PlayerID AND MatchNumber NOT IN MatchdayScore

 

So it only shows players who haven't got match 12 in MatchdayScore, but i'm not sure how i'd go about this?

 

Any advice massively appreciated.

 

Thanks

Many thanks Barand, made a few changes:

SELECT p.*
FROM Players p
  LEFT JOIN MatchdayScore m
    ON p.PlayerID = m.PlayerID AND m.MatchNumber = $matchday
WHERE m.PlayerID IS NULL AND ClubID = $ClubID

and works perfectly. Hope you're well buddy!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.