2

I need to do it in MS Access. I have two tables: A {id, name, FK to B} B {id, name, limit}

Now I need to create query which would give me Bs that have less A than its limit:

SELECT * FROM B WHERE B.limit <
   (SELECT COUNT(A.id) FROM A WHERE A.[FK to B] = B.id)

I have no idea how can I make query simple as this in MS Access.

1 Answer 1

2

Maybe you can do this with an OUTER JOIN and subquery instead:

SELECT B.*
FROM B 
    LEFT JOIN (
        SELECT Count(*) cnt, BID
        FROM A
        GROUP BY BID
    ) A ON B.Id = A.BID
WHERE B.limit < NZ(A.cnt,0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.