Re: Bizarre subquery syntax problem
- From: John Spencer <spencer@xxxxxxxxxx>
- Date: Sat, 17 May 2008 08:25:49 -0400
Also, a subquery in the from clause cannot CONTAIN any square brackets. Your field and table names require square brackets since they contain spaces. The only way to get this to work is to nest queries.
This is one reason to name tables and fields with names that contain only letters, numbers, and underscores.
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
Sylvain Lafontaine wrote:
With Access, the official syntax for a subquery always requires an alias, so you must write:.
SELECT Q.*
FROM (
SELECT p.[User id] AS UID, p.Firstname AS Firstname, p.Lastname AS Lastname,
p.Email AS Email, p.[Profiled member] AS Prof , Left(p.[Date updated],10) AS
Updated, Left(a.[Date last access],10) AS Accessed, (SELECT COUNT(*) FROM
[Users Profile (Detail)] AS q WHERE p.[Lastname] = q.[Lastname] AND
p.[Firstname] = q.[Firstname]) AS Num
FROM [Users Profile (Detail)] AS p LEFT JOIN [Users Address (detail)] AS a
ON p.[User id]=a.[User id]
) as Q;
Also, Access uses [ ... ]. and not the parenthesis () as the delimiter for a subquery (notice the point . after the right bracket ] ). However, if you uses parenthesis, Access will understand it. Sometime, it will rewrite (replace) them with []. and sometime, it will not.
Finally, as you have noticed, Access is very weak at understanding queries with multiple Left and Right Outer Join and with Subqueries; especially but not necessarily if you mix both. There is no point of coming here to say that Access doesn't understanding one of your queries, rewrites it (correctly or - worse - incorrectly) or even simply choose to core-dump when you try to execute it.
In some cases, explicitely dividing a big query into multiples queries in the Queries collection might help but the only thing to do might be often to use temporary tables or to use simpler queries in association with DLookup() and DCount() on the form or the report to complete the result.
- Follow-Ups:
- Re: Bizarre subquery syntax problem
- From: colin_e
- Re: Bizarre subquery syntax problem
- References:
- Bizarre subquery syntax problem
- From: colin_e
- Re: Bizarre subquery syntax problem
- From: Sylvain Lafontaine
- Bizarre subquery syntax problem
- Prev by Date: Re: Bug in ODBC?
- Next by Date: Re: Bug in ODBC?
- Previous by thread: Re: Bizarre subquery syntax problem
- Next by thread: Re: Bizarre subquery syntax problem
- Index(es):
Relevant Pages
|