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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(SELECT COUNT(*) FROM TableA a WHERE a.SameIDs = b.SameIDs) AS TheCount
FROM TableB b
ORDER BY SameIDs