I have an SQL problem i was wondering if someone could help me out. Below is the schema of the database
Player
- playerid (primary key)
- playerName
PlaysAt
- clubId (primary key)
- playerId (fk to PLAYER.playerid)
- yearsAtClub
My question is how do i select the clubId of the club where player named john and stephen play where john and stephen play at the same club. I have no idea how to get the club id in this case. i have managed to get the join part correct as im able to select the club id of john but cant get it when i specify the both players using WHERE playerName = john AND playerName = stephen.
Use:
The key is that the number of parameters in the IN clause needs to match the COUNT in the HAVING clause — in this case, two.
The DISTINCT helps in case there isn’t a primary key or unique constraint on both the
PLAYSAT.clubidandPLAYSAT.playeridcolumns — two entries for “John” otherwise would be considered valid if for the same clubid value. Otherwise, the DISTINCT can be omitted from the query.