how to use Exists function in ms access

Ir4Qe DesiGner 1 Reputation point
2021-10-16T05:56:03.593+00:00

hi guys. i have database ms access 2010
i have 3 tables

141025-image.png
140964-image.png
140982-image.png

i need search who customer not have materials selected in table orders
example:

i select materials:

Stereo
Lamp

i need get who customer not have this material in table orders
the result should be:

Customers:
2 beghy
[4] john

DOWNLOAD DATABASE:

https://hostr.co/qnqzGkWdY1aP

Microsoft 365 and Office Access Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DBG 2,381 Reputation points Volunteer Moderator
    2021-10-16T17:45:37.823+00:00

    Hi. Not sure if this is correct, but here goes...

    SELECT T1.Id, CustomerName
    FROM tbl_customers T1
    LEFT JOIN tbl_orders T2
    ON T1.Id=T2.CustomerId
    WHERE NOT EXISTS(SELECT * FROM tbl_orders S1
    WHERE S1.CustomerId=T1.Id AND S1.MaterialId IN(SELECT Id FROM tbl_materials WHERE Selected=True))
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.