Your tables are wrongly designed, I'm afraid. By storing the days
availabilities as Boolean (Yes/No) columns you are doing what's known as
'encoding data as column headings'. Data should only be stored as values at
column positions in rows in tables. What you should have are separate tables
CustomerAvailability with columns CustomerID and DayAvailable, and
InstallerAvailabilty with columns InstallerID and DayAvailable, so if
Customer 42 is available on Monday's and Tuesdays only there would be rows in
CustomerAvailability:
42 2
42 3
The second column should reference a DaysOfWeek table with 7 rows 1 Sunday,
2 Monday etc. By enforcing referential integrity in the relationships
between this and CustomerAvailability and InstallerAvailabilty you can't
enter a non-existent day (day 8 of the week for example).
To find matching Customers, Installers on Mondays say:
SELECT DISTINCT Installer, Customer
FROM Installers, InstallerAvailability, Customers, CustomerAvailability
WHERE Installers.InstallerID = InstallerAvailability.InstallerID
AND Customers.CustomerID = CustomerAvailability.CustomerID
AND InstallerAvailability.DayAvailable = 2
AND CustomerAvailability.DayAvailable = 2;
This joins Installers to InstallerAvailability and Customers to
CustomerAvailability by means of the join criteria in the WHERE clause, and
restricts each to those available on Mondays (day 2). As the results of
these two joins are not joined by any criteria it joins every row from each
with every row from the other (what's known as the Cartesian product of the
two sets) so what you get is all possible combinations of Installer/Customer
on Mondays.
Ken Sheridan
Stafford, England