jimmytiler
jimmytiler

Reputation: 83

Adding Sub-queries

I'm trying to execute a SQL that will result in displaying the athletes that came 1st, 2nd, or 3rd from a series of races. My problem is trying to add into the question 'only' athletes who have met this criteria two or more times?

SELECT 
    athlete.athlete_id, athlete.name, race.place
FROM
    athlete
        INNER JOIN
    race ON race.athlete_id = athelete.athlete_id
WHERE
    race.place IN (1, 2, 3); 

Running the above SQL displays only displays the athletes who have come 1st, 2nd, or 3rd. How do I add the second part to my SQL?

Upvotes: 0

Views: 27

Answers (1)

kentor
kentor

Reputation: 18504

SELECT 
    athlete.athlete_id, athlete.name, race.place
FROM
    athlete
        INNER JOIN
    race ON race.athlete_id = athelete.athlete_id
WHERE
    race.place IN (1, 2, 3); 
GROUP BY
    athlete.athlete_id
HAVING count(athlete.athlete_id) >= 2

Try this.

Upvotes: 1

Related Questions