View Single Post
  #5  
Old March 7th, 2006, 06:07 PM posted to microsoft.public.access.queries
external usenet poster
 
Posts: n/a
Default Correlated Subquery doesn't work

Dear Geesh:

If there is a tie for first place, TOP 1 will return more than one row. In
the context of your subquery this would mean you have multiple rows for the
specified GaugeID with the same maximum value of NextCertDue. You might
want to check this.

I recommend changing the subquery:

(SELECT MAX(NextCertDue)
FROM tblWorkLog wl
WHERE GaugeID =tblWorkLog_Main.GuageID
AND WorkLogID 1) AS DueDate

I believe that should fix the new problem.

Tom Ellison


"D Witherspoon" wrote in message
...
Geesh ! Thanks...

Now I get this problem however....

It seems that it doesn't like using Top 1. Arg!

At most one record can be returned by this subquery. (Error 3354)
A subquery of this kind cannot return more than one record. Revise the
SELECT statement of the subquery to request only one record.

"Tom Ellison" wrote in message
...
Dear D:

You have misspelled "Gauge" as "Guage"

That should do it!

Tom Ellison


"D Witherspoon" wrote in message
...
Whenever I try and run this query a pop-up box comes up asking for the
value of tblWorkLog_Main.GuageID.

Why is this happening. According to the following 2 articles my query
should work. I've never had this problem in SQL Server.
http://www.tek-tips.com/faqs.cfm?fid=4058
http://support.microsoft.com/?kbid=209066

Both queries work fine independantly (as long as I remove the reference
to tblWorkLog_Main in the sub query if I run it by itself).

I'm using MS Access 2000.


SELECT WorkLogID, GaugeID, NextCertDue,

(SELECT TOP 1 NextCertDue
FROM tblWorkLog wl
WHERE GaugeID =tblWorkLog_Main.GuageID
AND
WorkLogID 1
ORDER BY NextCertDue Desc) AS DueDate


FROM tblWorkLog tblWorkLog_Main
ORDER BY GaugeID, NextCertDue DESC;