Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND profile.profileId = 0 and team_tournament_mapping.is_paid = 1' at line 1 SELECT COUNT(team_tournament_mapping.team_tournament_mappingId) AS num FROM (`team_tournament_mapping` INNER JOIN team ON team.teamId = team_tournament_mapping.team_id) INNER JOIN profile ON profile.profileId = team.profile_id where team_tournament_mapping.tournament_id = AND profile.profileId = 0 and team_tournament_mapping.is_paid = 1