문제

I am trying to convert a query so it can be run on Access DB. For some reason access in the second part is throwing the exception

Syntax error in query expression '(Select count(p.id) FROM post p..."

Here you can see that everything works perfectly on SQL Server 2008: http://www.sqlfiddle.com/#!3/388fc/1

SELECT
   c.id,
   c.CategoryName,
   c.Description,
   (SELECT count(t.id)
    FROM topic t
    WHERE t.categoryId = c.id) AS NumberOfTopics,
   (SELECT count(p.id)
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id) AS NumberOfPosts,
   (SELECT top 1 max(p.createdOn) 
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id) AS LastPostDate,
   (SELECT top 1 createdby 
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id 
    ORDER BY p.createdon DESC) AS byperson
FROM 
   category c;

Thank you

도움이 되었습니까?

해결책

Access requires that you indicate the type of join: inner; left; or right. It will not accept just JOIN as a synonym for INNER JOIN.

So make all of them INNER JOIN and see whether Access surfaces any other complaints.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top