Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top