I have this SQL in Access, but it is giving me an error. I’ve tried moving the parenthesis around but it hasn’t resolved the issue.
SELECT
a.title, a.id, a.name, l.user, l.time
FROM
Reports a
INNER JOIN (
AuditLog AS l ON a.id = l.id
INNER JOIN (
(
SELECT min(time) Mintime, id
from AuditLog
GROUP BY id
) AS t )
ON l.id = t.id
AND l.time = t.mintime )
WHERE
a.NAME LIKE 'something*'
AND a.ACTIVE='Y'
How can I resolve the syntax errors I’m getting?
This piece of your query should definitely create a problem:
If you intend to alias the field expression
min(time)asMintime, you must use theASkeyword. You don’t needASfor a table alias but you do for a field alias:It seems
timeis a field in yourAuditLogtable. In that case enclose its name in square brackets to distinguish it from theTime()function:As for the parentheses, you should use Access’ query designer to set up your joins if possible. It will guarantee your query includes the parentheses the db engine demands and will position them correctly.
If that’s not an option, give this untested version a try: