Correllated Subquery, unresolving outer references



I'm trying to form a correlated subquery (right now, it's MS Access
running to linked tables in MS SQL, although I have tried to make the
same query against the MS SQL tables directly).

The goal in the query below is to filter out near-duplicates.

What I have is similar rows in my database, and the differences between
the different rows lies in a date field. I want to be able to filter
out the "newest" dates

What happens is that Access treats all of the references in the
subquery as variables to be filled (and so prompts me), but if I use
the full table name, it defeats the purpose of a corellated subquery
(namely, to be able to use an outer reference).

SELECT dbo_ace_sites.longName, dbo_ace_taskCore.onsiteDate,
dbo_ace_taskCore.status
FROM dbo_ace_taskCore AS A1, dbo_ace_sites AS A2
WHERE (((A1.site)=[A2].[shortCode]) AND [A1].[onsiteDate] Between
DateValue("1/1/2006") and DateValue("7/1/2006") AND
(([dbo_ace_taskCore].[onsiteDate]) In (select Max(A1.onsiteDate)
FROM dbo_ace_taskCore A3 WHERE A3.shortCode = A1.shortCode )));

I'd love either a explanation of what's going wrong here, or how to fix
it, or a link explaining exactly how to write outer references with MS
SQL/Access (and the guide at
http://www.aspfree.com/c/a/MS-SQL-Server/Subqueries-and-Query-Expressions/2/
isn't the proper syntax).

Thanks

.



Relevant Pages

  • Query Multiple Tables
    ... Actually the subquery is just pure sql language, ... query, switch to SQL view, copy the text, and then paste ... >DMax in a query criteria in the same way. ...
    (microsoft.public.access.queries)
  • Re: Trouble with query
    ... What you have here is known as a correlated subquery. ... "outer" query, the "inner" query is processed, based on the correlation ... Various books on SQL cover this. ... #transtype ty on tr.idtranstype = ty.idtranstype ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL Division
    ... however, is that you CANNOT, then have any brackets in your subquery. ... brackets and parentheses within the subquery ... the SQL text remains identical. ...
    (microsoft.public.access.queries)
  • Re: Help with derived table SQL statement in Access
    ... Table aliases increase the clarity of SQL by explicitly noting each ... If I remove the where clause from the subquery, it works, but I get ... SELECT expression on the FROM clause, but that is just that, a table ...
    (microsoft.public.access.queries)
  • Re: System.Data.SqlClient.SqlException: Subquery returned more than 1 value.
    ... The site is using SQL Server 7. ... > INSERT INTO OrderItems (ClientID, ProductID, OrderHeaderID, Quantity, ... Subquery returned more than 1 value. ... > Dim conn As New System.Data.SqlClient.SqlConnection ...
    (microsoft.public.dotnet.framework.aspnet)