Solved

Select unique records (members per household) in access

Posted on 2014-09-30
11
39 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 48

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 48

Expert Comment

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

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
 

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 48

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS - Date Report Options 2 30
AD and SQL Server 2016 2 31
Gracefully handling 'Record Locked'  Errors 33 37
SQL Sever 2010 View Join Does Not Return All Rows 14 16
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Viewers will learn how the fundamental information of how to create a table.

820 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