Hi, I am trying to build a query that joins 3 tables. I have used 2 LEFT OUTER JOINS to do this, however what I am finding is that the 3rd table is returning many records. I have been trying to return only the MAX(ID) from this 3rd table but no matter what I do it doesn't work or I get an error. What is the process to do something like this? I will attach my query below but I really want to get this working. I'm not sure how this is supposed to work.
(SELECT Task.ID AS TaskID, Task.VendorID, Task.Type, Task.Date, Vendor.Name AS [Name], Contract.ID AS [ContractID], Contract.Type, Contract.Status, Contract.StatusDate FROM Task LEFT OUTER JOIN Vendor ON Vendor.ID = Task.VendorID LEFT OUTER JOIN Contract ON Vendor.ID = Contract.VendorID WHERE (((Contract.ID) Is Null Or (Contract.ID) In (SELECT MAX(ID) AS MaxContractID FROM Contract GROUP BY VendorID))) WHERE Task.PersonelID = '" + [The User] + "' AND Task.CompletedBY IS NULL AND Task.Date< '" + [Date] + "' AND Task.VendorType = '" + [Type] + "')
Thanks for the help on this one everyone that helps. I thought I was on the right track but no matter what I do it fails for one reason or another (All different, so at least it's different issues. lol).