count distinct number of records in sql I have table that contain one is event Id ,second is school Id and third is game ID I want to count number of school who has participated in that event with unique game ID (One school can participate in multiple event with different game)  

Example    

Event Id   school ID   Game ID  
1          20          1  
3          21          2  
1          22          3         
2          22          4  
3          21          5  
1          20          6  


I need the output is   

Event Id        schoolCount  
1               2   
3               1  
2               1
Just use a simple and standardized GROUP BY and COUNT(DISTINCT ..)

CREATE TABLE foo(a,b,c)
AS VALUES 
    ( 1, 20, 1 ),
    ( 3, 21, 2 ),
    ( 1, 22, 3 ),    
    ( 2, 22, 4 ),
    ( 3, 21, 5 ),
    ( 1, 20, 6 );

SELECT a, COUNT(DISTINCT b)
FROM foo
GROUP BY a;