Solved

Select unique records (members per household) in access

Posted on 2014-09-30
11
33 Views
Last Modified: 2016-06-14
I need to select unique records from a table in access.  Setup first.

My table design is as follows - all text fields.

Transaction Name
Household Name
First Name
Last Name
Mailing Street
Mailing City
Mailing State/Province
Mailing Zip/Postal Code

I need to get only one full mailing address (First Name, Last Name, Mailing Street, Mailing City, Mailing State/Province, Mailing Zip/Postal Code) per distinct Household Name.

Can I do this with a subquery?
0
Comment
Question by:mattturley
  • 4
  • 4
  • 2
11 Comments
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40352404
What is the primary key for that table?
0
 

Author Comment

by:mattturley
ID: 40352408
None.
0
 

Author Comment

by:mattturley
ID: 40352411
I could make it transaction name.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40352423
Should be a column that can identify an unique record.
0
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40352444
Assuming Transaction Name as PK this can be a solution:
SELECT T1.FirstName, T1.LastName, T1.MailingStreet, T1.MailingCity, T1.MailingState, T1.MailingZip
FROM YourTableNameHere T1
WHERE T1.TransactionName = (SELECT TOP 1 T2.TransactionName 
                                                    FROM YourTableNameHere T2
                                                     WHERE T2.MailingStreet=T1.MailingStreet
                                                          AND T2.MailingCity=T1.MailingCity
                                                          AND T2.MailingState=T1.MailingState
                                                          AND T2.MailingZip=T1.MailingZip)

Open in new window

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:mattturley
ID: 40352661
I'm a little confused - are you creating a table or aliasing part of the query as a table?
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40352739
It would be better to have a separate Households table, with a HouseholdID key field.  Then put that key into the Persons table, as a foreign key.  The address fields should be in tblHouseholds, which would have one record per household.  Though you might run into problems with divorced couples, where a child could be moving between two households in a joint custody arrangement.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40352743
Having the address repeated for each person means that if there is a change of address, you will have to go into each person's record and change the address; if they are in a Households table, you only need to change it once.

What is a transaction?  Depending on the answer to that question, you might need yet another table.
0
 

Author Comment

by:mattturley
ID: 40352947
While I appreciate the best practice on table structure, naming, field names, etc., I am just working with what was given to me.  Would prefer a solution that keeps the query going against the single table, as identified in the question.
Thanks!
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40353983
No new tables. Only aliases since the query works with the same table twice, so you need to provide alias for the engine know to each one are you referring to.
Did you test it?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report Builder 9 31
Azure SQL DB? 3 22
Pass Form Control to VBA Function 2 27
Split Data in 1 column into 2 columns 8 21
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now