Hi everyone I have a problem with a SQL query and I can not find a solution.
In my database I have two tables, Mytable1 and Mytable2. Mytable1 contains columns idCalendar, idPlayer, datePlaying and Mytable2 contains columns idPlayer and namePlayer.
I want to extract foreach date in Mytable1 the names of players who did not play.
For example
Mytable1 (contains player and playing date):
idCalendar|idPlayer|datePlaying
1 | 1 | 05/01/2012
2 | 2 | 06/01/2012
3 | 3 | 08/01/2012
4 | 2 | 05/01/2012
Mytable2 (contains all player names) :
idPlayer|namePlayer
1 | P1
2 | P2
3 | P3
4 | P4
I’d like to create a view that displays the following result :
ViewResult (players who haven’t played by date):
datePlaying | playerName
05/01/2012 | P2
05/01/2012 | P3
06/01/2012 | P1
06/01/2012 | P3
08/01/2012 | P1
08/01/2012 | P2
As you can see I need result with this information:
– in 05/01/2012 P2 and P3 haven’t played.
– in 06/01/2012 P1 and P3 haven’t played.
– in 08/01/2012 P1 and P2 haven’t played.
I hope I have been clear enough. Thank you in advance.
Probably something as simple as this would work.
As a side note what happens if you have a date where non of the players played? You wouldnt have an entry in table2. Do you care or should there be a 3rd table to represent dates that any of the players should have played. This dates table would be used to replace my alias ‘d’ cross-joined table.