Mysql – Find missing entries across several tables by SQL call

MySQL

I was already browsing around here and on other platforms but could not find a match to my request. My knowledge of SQL is quite limited and my IT department is not willing to help unfortunately.

I have 7 different tables (‚Sys1, Sys2…Sys7‘), with columns 'name' and 'date'.

An 8. table (‚summary‘) also has columns ‚name‘, ‚date‘ and additionally ‚sys‘. ‚sys‘ can have values ‚Sys1‘ to ‚Sys7‘. I want to compare if entries in tables ‚Sys1-7‘ also appear in table ‚summary‘ and vice versa. The reference for it is values in the column ‚sys‘. 'Name' and 'date' are the same in both tables. However, it is possible that name-date-combinations appear twice in one table, it is also possible that the same name-date-combination appears in two or more ‚Sys‘ tables.
I am finally only interested to know, if there are entries that have NOT been made with name and date in both tables (Sys1-7 AND summary).

An example:

Table ‚Sys1‘:
| Name          | date     |
|---------------|----------|
|Max Mustermann |01.12.2020|

Table ‘Sys2’:
|Name           | date       |
|---------------|------------|
|Hans Wurst     | 01.12.2020 |
|Max Mustermann | 01.12.2020 |
|Donald Trump   | 01.12.2020 |

Table ‘summary’:
| Name          | date       | sys  |
|---------------|------------|------|
|Max Mustermann | 01.12.2020 | Sys1 |
|Hans Wurst     | 01.12.2020 | Sys2 |
|Max Mustermann | 01.12.2020 | Sys2 |
|Joe Biden      | 01.12.2020 | Sys1 |

So here I want to see that Donald Trump did not sign into table 'summary' and Joe Biden did not sign in table 'Sys1'.

Thanks for any help or link to answered questions I might have missed

Best Answer

SELECT *
FROM SysN sy
WHERE NOT EXISTS ( SELECT NULL
                   FROM summary su
                   WHERE (su.name, su.date, su.sys) = (sy.name, sy.date, 'SysN') )

Execute 7 separate queries or combine them via UNION ALL into one query.