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

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
  • Thanks for that! Somehow I didn't think of just using an INNER JOIN -.- – user3202098 Jul 7 '16 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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