INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help needed updating a table

Help needed updating a table

(OP)
hello

I am asking for help writing a query (or, possibly, VBA).

Consider two tables, tblA and tblB.

CODE

tblA   [PK: X, Y, c]                                           tblB    [PK: X, c, r]

    X         Y         c       MatchCount                         X         c        r
  -------------------------------------------                     -----------------------
    ...                                                            ...
    25        33        6           0                              24        7        3
    25        33        9           0                                
                                                                   25        2        8
    25        34        4           0                              25        4        6    
    25        34        5           0                              25        4        8    
    25        34        7           0                              25        5        6
    25        34        8           0                              25        5        8    
    25        34       10           0                              25        8        6    
                                                                   25       10        6
    25        35        1           0                              25       10        8    
    25        35        2           0                                
    25        35        8           0                              26        7        4
    25        35       10           0                              26        9        8
    ...                                                            ... 

For each X, Y grouping in tblA, I want to match the two tables on X and c, then UPDATE tblA's MatchCount column to show the number
of matches. For the example shown, the tblA should end up looking like this...

CODE

tblA   [PK: X, Y, c]  
                    
    X         Y         c       MatchCount    
  -------------------------------------------   
    ...                              
    25        33        2           1
    25        33        9           0                                
                                      
    25        34        4           2
    25        34        5           2  
    25        34        7           0
    25        34        8           1 
    25        34       10           2
                                      
    25        35        1           0
    25        35        2           1
    25        35        8           1
    25        35       10           2 
    ... 

Thank you for any assistance
Teach314

RE: Help needed updating a table

hi,

This objective can be accomplished by a simple query, not an update query, since calculated fields such as this should never be a table field.

CODE

SELECT A.X, A.Y, A.c, Count(*) As MatchCount
FROM tblA A LEFT OUTER JOIN B tblB ON A.c = B.c
WHERE A.X = B.X
GROUP BY A.X, A.Y, A.c; 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Help needed updating a table

(OP)
Much better. Thanks, Skip.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close