I am trying to count how many times each ID appears in a specific table as follows.
Members
ID | NAME
1 | Bob
2 | John
3 | Sally
4 | Hannah
Department
ID | DEPT
1 | Math
1 | English
3 | Math
4 | Math
4 | English
4 | Science
I would like to display a table as follows:
ID | Name | Count(Dept)
1 | Bob | 2
2 | John | 0
3 | Sally | 1
4 | Hannah | 3
I have made several attempts at this my most recent one being:
select owner
from table
where (select count(distinct letter) from table group by owner) in
(select max(count(distinct letter)) from table group by owner);
I just cannot seem how to get the 0 results to show properly. Honestly, i'm kinda confused as to how to use on ... when you don't want to basically preform a natural join.
edit: I have edited the question to properly show what I am trying to ask. Sorry for any confusion.