Solved

Select unique records (members per household) in access

Posted on 2014-09-30
11
42 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 50

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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 50

Expert Comment

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

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 50

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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