?
Solved

Select unique records (members per household) in access

Posted on 2014-09-30
11
Medium Priority
?
43 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
11 Comments
 
LVL 51

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 51

Expert Comment

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

Accepted Solution

by:
Vitor Montalvão earned 2000 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 51

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

764 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