Get startedGet started for free

In CASE of rivalry

Barcelona and Real Madrid have been rival teams for more than 80 years. Matches between these two teams are given the name El Clásico (The Classic). In this exercise, you will query a list of matches played between these two rivals.

You will notice in Step 2 that when you have multiple logical conditions in a CASE statement, you may quickly end up with a large number of WHEN clauses to logically test every outcome you are interested in. It's important to make sure you don't accidentally exclude key information in your ELSE clause.

In this exercise, you will retrieve information about matches played between Barcelona (id = 8634) and Real Madrid (id = 8633). Note that the query you are provided with already identifies the Clásico matches using a filter in the WHERE clause.

This exercise is part of the course

Data Manipulation in SQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT 
	date,
	-- Identify the home team as Barcelona or Real Madrid
	___ ___ ___ = 8634 ___ 'FC Barcelona' 
        ___ 'Real Madrid CF' ___ ___ home,
    -- Identify the away team as Barcelona or Real Madrid
	___ ___ ___ = 8634 ___ 'FC Barcelona' 
        ___ 'Real Madrid CF' ___ ___ away
FROM matches_spain
WHERE (awayteam_id = 8634 OR hometeam_id = 8634)
      AND (awayteam_id = 8633 OR hometeam_id = 8633);
Edit and Run Code