Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

Need to build an SQL query with a count and 2 tables

I have 2 tables. Table A has a column called SameIDs, Table B also has a column called SameIDs. In Table B, the SameIDs column will only have unique entries, but in table A it can have many with the same results in that column.  I need to query the results of Table B, and also create a column in my query to count the number of times the unique entry is listed in Table A. Below are sample tables and what I'd like the query to output... can someone help? Thank you!

Table A                      Table B      
SameIDs                   SameIDs           Notes           Date
     5                               5                    fake note     9/18/15
     5                               7                    test note      9/18/15
     5
     7
     7

I want the query to output this:

 SameIDs    Notes           Date            TheCount
          5     fake note     9/18/15                    3
          7     test note      9/18/15                    2
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT b.SameIDs, b.Notes, b.Date,
    (SELECT COUNT(*) FROM TableA a WHERE a.SameIDs = b.SameIDs) AS TheCount
FROM TableB b
ORDER BY SameIDs