Using MS Access/Access 2003 SQL

Advertisement


Question
I have a table name tblAddress with fields :
AddressId  Autonumber  Primary Key
Surname    Text
Name       Text
Address    Text
and a table name tblDonations with fields :
AddressId  Number
DonationDate Date
Amount       Number
Relations one to many on AddressId
How can I get a query to pull up only Benefactors ( AddressId ) who have never donated in last 3 years? Thanks

Answer
First you should have a Primary key field in tblDonations. Then you need to use a subquery for this.

You create a query on tblAddress with a subquery as the critery for AddressID

NOT IN(SELECT DISTINCT AddressID FROM tblDonations WHERE DonationDate > DateAdd("yyyy",-3,Date()))

So the subquery finds all those who have made a donation in the last three years and the criteria filters out those people.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.