Skip to content
Exercises · Q6

Q.Using the sports database containing two relations (TEAM, MATCH_DETAILS), answer the following relational algebra queries.

a) Retrieve the MatchID of all those matches where both the teams have scored > 70.
b) Retrieve the MatchID of all those matches where FirstTeam has scored < 70 but SecondTeam has scored > 70.
c) Find out the MatchID and date of matches played by Team 1 and won by it.
d) Find out the MatchID of matches played by Team 2 and not won by it.
e) In the TEAM relation, change the name of the relation to T_DATA. Also change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
Puducherry CbseNCERTSubjective· 4mImportance★★★★★est
71% · 32/45 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Each part is a relational-algebra idea (selection, projection, rename) executed in SQL: filters with WHERE on the score columns, an OR over "team played as first OR as second" for the win/loss parts, and ALTER TABLE ... RENAME for the rename operation. Results from the given data: (a) M1,

(b) M5,

(c) M1 and M3,

(d) M1 and M4.

In relational-algebra terms: selection (choosing rows by condition) becomes WHERE, projection (choosing columns) becomes the SELECT list, and rename (the rho operation) becomes ALTER TABLE ... RENAME. Data used (MATCH_DETAILS): M1 1v2 90-86, M2 3v4 45-48, M3 1v3 78-56, M4 2v4 56-67, M5 1v4 32-87, M6 2v3 67-51.

a) Matches where both teams scored more than 70

SELECT MatchID
FROM MATCH_DETAILS
WHERE FirstTeamScore > 70 AND SecondTeamScore > 70;
MatchID
M1

Only M1 qualifies (90 and 86). AND demands both conditions hold — M5's 87 fails because its partner score is 32.

b) FirstTeam scored below 70, SecondTeam above 70

SELECT MatchID
FROM MATCH_DETAILS
WHERE FirstTeamScore < 70 AND SecondTeamScore > 70;
MatchID
M5

M5 alone: 32 < 70 and 87 > 70.

c) Matches played by Team 1 and won by it

Team 1 can appear as either the first or the second team, so the win test has two branches joined by OR:

SELECT MatchID, MatchDate
FROM MATCH_DETAILS
WHERE (FirstTeamID = 1 AND FirstTeamScore > SecondTeamScore)
   OR (SecondTeamID = 1 AND SecondTeamScore > FirstTeamScore);
MatchIDMatchDate
M12018-07-17
M32018-07-19

Team 1 played M1 (won 90-86), M3 (won 78-56) and M5 (lost 32-87) — the WHERE keeps only the wins.

d) Matches played by Team 2 and NOT won by it

Same two-branch shape, with the comparison flipped to "scored less":

SELECT MatchID
FROM MATCH_DETAILS
WHERE (FirstTeamID = 2 AND FirstTeamScore < SecondTeamScore)
   OR (SecondTeamID = 2 AND SecondTeamScore < FirstTeamScore);
MatchID
M1
M4

Team 2's matches: M1 (86 vs 90 — lost), M4 (56 vs 67 — lost), M6 (67 vs 51 — won, so excluded). …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.