The base query would look something like this:who played against another player
SELECT
P1.PlayerID AS Player1,
P2.PlayerID AS Player2,
P1.GameResID
FROM
GamePlays AS P1
INNER JOIN GamePlays AS P2
ON P1.GameID = P2.GameID
WHERE
P1.PlayerID < P2.PlayerID
Example: Player A played againd Player B 10 times and won 5 games lost 2 and draw 3 games
SELECT
P1.PlayerID AS Player1,
P2.PlayerID AS Player2,
Abs(SUM(P1.GameResID = 1)) AS won,
Abs(SUM(P1.GameResID = 0.5)) AS draw,
Abs(SUM(P1.GameResID = 0)) AS lost
FROM
GamePlays AS P1
INNER JOIN GamePlays AS P2
ON P1.GameID = P2.GameID
WHERE
P1.PlayerID < P2.PlayerID
GROUP BY
P1.PlayerID,
P2.PlayerID
I guess you've never encountered a m-m relationship where both sides were the same table and which also included intersection data. A chess match which records the two players as white and black along with date, location, winner is one. Another is a marriage which records the two partners as husband and wife or if you're woke as partner1 and partner2 along with date and location also.The need for a union query indicates a structural error in the majority of cases, even more so if this is the very first step in the processing.
You're guessing wrong.I guess you've never encountered a m-m relationship where both sides were the same table
If this is the form discussed above: Only new records are created - 3 records per transaction, one of which has a date - no changes are made.When I open the newEntryForm
If this is the form discussed above: Only new records are created - 3 records per transaction, one of which has a date - no changes are made.
So it should be clear to check where you got this date from.
SELECT
N1.PlayerNickName AS Nick1,
N2.PlayerNickName AS Nick2,
Abs(SUM(P1.GameResID = 1)) AS won,
Abs(SUM(P1.GameResID = 0.5)) AS draw,
Abs(SUM(P1.GameResID = 0)) AS lost
FROM
(
(GamePlays AS P1
INNER JOIN GamePlays AS P2
ON P1.GameID = P2.GameID
)
INNER JOIN Players AS N1
ON P1.PlayerID = N1.PlayerID
)
INNER JOIN Players AS N2
ON P2.PlayerID = N2.PlayerID
WHERE
P1.PlayerID < P2.PlayerID
GROUP BY
N1.PlayerNickName,
N2.PlayerNickName
Hi Eberhard,How to get from PlayerID to PlayerNickname?
Link the necessary table Players and use its fields.
Grouping via PlayerNickName suggests setting an index on this field - if your users are busy and have a lot of games to evaluate.SQL:SELECT N1.PlayerNickName AS Nick1, N2.PlayerNickName AS Nick2, Abs(SUM(P1.GameResID = 1)) AS won, Abs(SUM(P1.GameResID = 0.5)) AS draw, Abs(SUM(P1.GameResID = 0)) AS lost FROM ( (GamePlays AS P1 INNER JOIN GamePlays AS P2 ON P1.GameID = P2.GameID ) INNER JOIN Players AS N1 ON P1.PlayerID = N1.PlayerID ) INNER JOIN Players AS N2 ON P2.PlayerID = N2.PlayerID WHERE P1.PlayerID < P2.PlayerID GROUP BY N1.PlayerNickName, N2.PlayerNickName
(P1.GameResID = 1)
Eberhard,The need for a union query indicates a structural error in the majority of cases, even more so if this is the very first step in the processing.
The union query performs a normalization step => SAME information into the SAME column. In addition to the player column, the result and other things also have to be taken into account. If further normalization has to be carried out in the first step of processing via query - what is the previous normalization worth?
Everything that is then based on the union query no longer offers index usage. This is how you specifically prevent possible performance. Is that your recommendation?