0

I need to get the Club_ID of all the clubs that have more than one member;

Here is the sql:

CREATE TABLE `Members` ( `ID` INT NOT NULL AUTO_INCREMENT , `Club_ID` INT NULL , `Name` VARCHAR(45) NULL , PRIMARY KEY (`ID`) ); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('1', 'Jim'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('2', 'John'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('1', 'Bill'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('3', 'Stan'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('4', 'David'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('1', 'Tony'); INSERT INTO `Members` (`Club_ID`, `Name`) VALUES ('5', 'Oscar'); 

This should return Only Club_ID =1!

0

3 Answers 3

1
 SELECT COUNT(*), Club_ID FROM Members GROUP BY Club_ID HAVING COUNT(*) > 1 
Sign up to request clarification or add additional context in comments.

Comments

1
select Club_ID from Members group by Club_ID having count(*)>1 

Comments

0
select club_id from members group by club_id having count(distinct id) >= 2 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.