1

I'm using a SELECT statement to select multiple IDs and than use

GROUP BY ID
HAVING COUNT(*) = someNumber

to only have the IDs with a certain count.

What I however actually want to do is to select all those IDs that have the same count that they have in another table. I tried some variations of the following but couldn't get my desired result.

GROUP BY ID
HAVING COUNT(*) = (SELECT COUNT(entryName_ID) FROM entryNames)

Is it even possible to do what I want? And if so how?

1 Answer 1

1

If I understand your requirement correctly, You can try something like this.

This will get count per ID from table1 and table2 and then return only those records where T1.ID count matches the second table

SELECT T1.ID FROM
(
    SELECT ID,Count(*) c 
    From Table1 GROUP BY ID
) T1
INNER JOIN 
(
     SELECT ID,Count(*) c 
     From Table2 GROUP BY ID
) T2
ON T1.ID = T2.ID AND T1.c = T2.c
1
  • Thanks for that! Somehow I didn't think of just using an INNER JOIN -.- Commented Jul 7, 2016 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.