Hi
I have a little JOIN problem.
I have a costumer table, a company table, and the 2 tables are compared with some filters, to find the companies that matches the costumers request.
This works fine, but now I have added a date in the costumer table.
And I now have another table where the companies put in some dates where they are not available.
So it a costumer table:
CostumerID
RequestDate
A Company table:
CompanyID
And some company date.
And a Not Available table:
AvailabilityID
CompanyID
Date
The companies then puts in the data in the available table where they are not available.
All this means that a company should not be matched with the costumer if the company is not available on the costumers request data.
The problem is that if i write
SELECT * FROM costumers cu INNER JOIN companies ca ON (cu.requestdate != ca.date)
it will work if the company as only this one date in the table.
But if the company puts in more dates it doesn't work.
And exampel:
CostumerID 1
RequestDate 2007-03-03
AvailabilityID 1
CompanyID 5
Date 2007-03-03
AvailabilityID 2
CompanyID 5
Date 2007-03-04
In this exampel company 5 will still be matched with costumer 1 on the AvailabilityID 2 so when I GROUP BY CompanyID at the end to find the companies that matches it will still show company 5 because it matches (not equal) on the date 2007-03-04.
And the company 5 should not be matched at all, because they are not available on the costumers request date...
So how do I 'not include' a company id when one of his dates is the same as the request date.