I am doing a inner join between two tables where one is an association table, so there is a many to one relationship. I am trying to come up with a query that can decide if the key on the join exist more than once than store a value multiple in the update column, but not sure the efficient way to make this happen:
SELECT
MainTable.Name
FROM MainTable
INNER JOIN ASSN_Main ON MainTable.AppID = ASSN_Main.AppID
WHERE
EXISTS (SELECT
COUNT(MainTable.AppID)
FROM MainTable
INNER JOIN ASSN_Main ON MainTable.AppID = ASSN_Main.AppID
GROUP BY
MainTable.AppID
HAVING
(COUNT(MainTable.AppID)>1));
The problem is the subquery grabs the correct ones that have duplicates on the appid, but the main SELECT query grabs all appid names instead of only the ones that exist in the subquery. Not sure whats going wrong since the subquery is correct?