OsakaWebbie
Programmer
I have a table called contact:
As you can probably imagine, it relates to a table called person via PersonID.
I'm trying to do a pretty complex query that isn't working, and I've boiled the problem down to this part of it.
I can query thus, as a test using just one person:
But when I try to do a join like this:
x.Completed comes back as NULL. Can anyone see why?
Code:
`ContactID` int(11) unsigned NOT NULL auto_increment,
`PersonID` int(11) unsigned NOT NULL default '0',
`ContactTypeID` int(11) unsigned NOT NULL default '0',
`ContactDate` date NOT NULL default '0000-00-00',
`Description` text
I'm trying to do a pretty complex query that isn't working, and I've boiled the problem down to this part of it.
I can query thus, as a test using just one person:
Code:
SELECT c2.PersonID,MAX(c2.ContactDate) AS Completed FROM contact c2 WHERE c2.ContactTypeID IN (9,16,34,35,36,37,48,58,59) AND c2.PersonID=618
Code:
PersonID Completed
618 2012-01-17
Code:
SELECT p.PersonID, x.Completed FROM person p
LEFT JOIN (SELECT c2.PersonID,MAX(c2.ContactDate) AS Completed FROM contact c2 WHERE c2.ContactTypeID IN (9,16,34,35,36,37,48,58,59)) x
ON x.PersonID=p.PersonID
WHERE p.PersonID=618