If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Help finding single occurrences of value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-12, 07:56
Tjmertes Tjmertes is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Help finding single occurrences of value

Hi
I am helping a small nonprofit straighten out their data and I am stumped on how to best do something.

I have tables

Individual table with individual.id and family.reference
Financial table with individual.ID and and family refernce

Family refernce is an indexed field with duplicates

If the family refernce code in the individual table has only one occurrence with its value I need to assign the individual table.id to the individual.id in the financial table.

Example

Individual table

Id. Family refernce
1. Fam1
2. Fam1
3. Fam2
4. Fam3
5. Fam4
6. Fam4

For Id 3 and 4 I want to set the financial table rows with a family refernce of fam2 to have an individual Id of 4 and those with a family reference of family reference of fam3 to have an individual Id of 4. I do not want any action for fam1 or fam2 because they have more than one occurrence.

Not sure if this can be done in SQL. Thanks
Reply With Quote
  #2 (permalink)  
Old 01-24-12, 13:34
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
I'm not sure to understand what you want to achieve. For retrieving the rows having a unique family reference you can use:
Code:
SELECT Individual.Id, Individual.Family_reference
FROM Individual
WHERE Individual.Family_reference In (SELECT [Family_reference] 
                                      FROM   [Individual] 
                                      GROUP BY [Family_reference] 
                                      HAVING Count(*)=1 );
But I don't know for sure what you want to do from there: Create new rows in the other table ("Financial") or update existing rows?
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 01-24-12, 19:44
Tjmertes Tjmertes is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Thanks,

I will try that. I then want to update the financial_table.individual_id with the individual_table.id for the selected rows. Thank you.
Reply With Quote
  #4 (permalink)  
Old 01-24-12, 22:33
Tjmertes Tjmertes is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
It worked

Thank you very much
Reply With Quote
  #5 (permalink)  
Old 01-25-12, 02:48
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
You're welcome!
__________________
Have a nice day!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On