I'm having problem with getting right value in Comment and ImageID.
SELECT
C.*,
E.*,
B1.ImageID AS LatestImageID,
B2.Comment AS LatestComment
FROM ((Customers C LEFT JOIN Employees E ON C.EmpID = E.EmpID) LEFT JOIN
blog B1 ON B1.[CustomerID] = C.[CustomerID]) LEFT JOIN
blog B2 ON B2.[CustomerID] = C.[CustomerID]
WHERE Username = '" & username & "'
AND ActiveCust = TRUE
AND B1.PostDate=(SELECT Max(PostDate) FROM blog where [CustomerID] = C.[CustomerID] AND B1.[ImageID] IS NOT NULL)
AND B2.PostDate=(SELECT Max(PostDate) FROM blog where[CustomerID] = C.[CustomerID] AND B2.[Comment] IS NOT NULL)
ORDER BY LastLogin DESC
The subquery ("ImageID is NOT NULL" and "Comment IS NOT NULL") in Where Clause is not working properly and gets ImageID and Comment that has Latest Post Date.
So in this case I get only Image ID because comment is also based on Post Date.
customer ID | Comment | PostDate | ImageID
001 Hi 1/5/2008
001 1/10/2008 066.jpg
Any Solutions?
Thanks
Start Free Trial