Advertisement

05.15.2008 at 12:23PM PDT, ID: 23406413
[x]
Attachment Details

SQL Subquery not working properly (MS ACCESS)

Asked by jtuttle99 in SQL Query Syntax

Tags: SQL ASP

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?

ThanksStart Free Trial
[+][-]05.15.2008 at 01:25PM PDT, ID: 21577648

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 07:34PM PDT, ID: 21579603

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 08:20PM PDT, ID: 21579760

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.19.2008 at 04:06PM PDT, ID: 21602342

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 04:40AM PDT, ID: 21605164

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Query Syntax
Tags: SQL ASP
Sign Up Now!
Solution Provided By: Thomasian
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628