C
colin_e
Guys, just back to Access after some time away (and I wasn't much good the
first time...)
I am seeing bizarre problems with a subquery.
1) I am joining two tables of user account data on a "User id" field. The
core query runs fine-
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];
2) Now, of a query "Q" works, then wrapping it in an outer query-
SELECT * FROM( Q );
must also work, by definition, no?
However this-
SELECT *
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]
);
fails with an error "syntax error in FROM clause".
3) Now it gets really interesting. By trying every combination of
adding/deleting spaces and carriage returns to the query, I actually got a
slightly more complex version (with an outer ORDER BY) clause to run.
When I closed and reopened this query in Access, two things happened-
3.1) Access had changed the syntax to-
SELECT *
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 [%$##@_Alias]
ORDER BY Num DESC , Lastname, Firstname;
Notice the square brackets around the subquery, with a "].", and what the
heck is that "%$##@_Alias" construct?
3.2) It's almost impossible to edit! If I edit this resulting query in any
way, even by deleting a space character, then reinserting the same space,
Access decides the query has a syntax error and refuses to run it. I'm
slightly nonplussed, I though SQL was as insensitive to whitespace as HTML, C
etc?
Any ideas on what's going on, and how to deal with it, much appreciated.
first time...)
I am seeing bizarre problems with a subquery.
1) I am joining two tables of user account data on a "User id" field. The
core query runs fine-
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];
2) Now, of a query "Q" works, then wrapping it in an outer query-
SELECT * FROM( Q );
must also work, by definition, no?
However this-
SELECT *
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]
);
fails with an error "syntax error in FROM clause".
3) Now it gets really interesting. By trying every combination of
adding/deleting spaces and carriage returns to the query, I actually got a
slightly more complex version (with an outer ORDER BY) clause to run.
When I closed and reopened this query in Access, two things happened-
3.1) Access had changed the syntax to-
SELECT *
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 [%$##@_Alias]
ORDER BY Num DESC , Lastname, Firstname;
Notice the square brackets around the subquery, with a "].", and what the
heck is that "%$##@_Alias" construct?
3.2) It's almost impossible to edit! If I edit this resulting query in any
way, even by deleting a space character, then reinserting the same space,
Access decides the query has a syntax error and refuses to run it. I'm
slightly nonplussed, I though SQL was as insensitive to whitespace as HTML, C
etc?
Any ideas on what's going on, and how to deal with it, much appreciated.