Lets say I have 2 tables:
"tblContactDeta ils" with fields "ContactID" and "UserName" and
"tblCommTra ck" with fields "CommTrackI D", "ContactID" , "CommType", "DateContac ted"
Case one: tblCommTrack has one row with values: 1,10,1, 2008-03-13 respectively. The following query works, because it doesn't return any rows for the indivudual with ContactID=10 WHERE CommType=1 AND DateContacted=2 008-03-13
[CODE=mysql] SELECT DISTINCT(d.Cont actID), d.UserName FROM tblContactDetai ls AS d Left Join tblCommTrack AS c ON d.ContactID = c.ContactID WHERE (c.CommTrackID IS NULL OR c.CommType=2 OR (c.DateContacte d <> 2008-03-13) ORDER By d.UserName[/CODE]
Case two: tblCommTrack has two rows with values: 1,10,1, 2008-03-13 and 1,10,2, 2008-03-13 Now the query doesn't work, because a record for individual with ContactID=10 is returned, and I don't want that. I only want to return records for individuals who don't have a value of 1 in the CommType field AND if the record with CommType=1 has DateContacted=2 008-03-13.
"tblContactDeta ils" with fields "ContactID" and "UserName" and
"tblCommTra ck" with fields "CommTrackI D", "ContactID" , "CommType", "DateContac ted"
Case one: tblCommTrack has one row with values: 1,10,1, 2008-03-13 respectively. The following query works, because it doesn't return any rows for the indivudual with ContactID=10 WHERE CommType=1 AND DateContacted=2 008-03-13
[CODE=mysql] SELECT DISTINCT(d.Cont actID), d.UserName FROM tblContactDetai ls AS d Left Join tblCommTrack AS c ON d.ContactID = c.ContactID WHERE (c.CommTrackID IS NULL OR c.CommType=2 OR (c.DateContacte d <> 2008-03-13) ORDER By d.UserName[/CODE]
Case two: tblCommTrack has two rows with values: 1,10,1, 2008-03-13 and 1,10,2, 2008-03-13 Now the query doesn't work, because a record for individual with ContactID=10 is returned, and I don't want that. I only want to return records for individuals who don't have a value of 1 in the CommType field AND if the record with CommType=1 has DateContacted=2 008-03-13.
Comment