Skip to content
Question
Q.

Consider the following tables PARTICIPANT and ACTIVITY :

Table : PARTICIPANT

ADMNONAMEHOUSEACTIVITYCODE
6473Kapil ShahGandhiA105
7134Joy MathewBoseA101
8786Saba AroraGandhiA102
6477Kapil ShahBoseA101
7658Faizal AhmedBhagatA104

Table : ACTIVITY

ACTIVITYCODEACTIVITYNAMEPOINTS
A101Running200
A102Hopping bag300
A103Skipping200
A104Bean bag250
A105Obstacle350

Write command in SQL for the following : (iii) To display Names of Participants along with Activity Codes and Activity Names for only those participants who are taking part in Activities that have ‘bag’ in their Activity Names and Points of activity are above 250.

CBSECBSE Class XII Board 2019Subjective· 2mImportance★★★★★
🔒 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 →

To display participant names, activity codes, and activity names for specific activities, we must join the PARTICIPANT and ACTIVITY tables and then filter the results based on the activity name containing 'bag' and having points above 250.

When working with relational databases, information is often spread across multiple tables to maintain efficiency and avoid redundancy. To answer questions that require data from more than one table, we need to establish a link between them. In this scenario, we want to see participant names alongside details of their activities, which means we need to combine data from the PARTICIPANT table and the ACTIVITY table.

The key to linking these two tables is the ACTIVITYCODE column. Both tables contain this column: ACTIVITYCODE in the ACTIVITY table uniquely identifies each activity (acting as its primary key), and ACTIVITYCODE in the PARTICIPANT table indicates which activity a participant is involved in (acting as a foreign key). This common column allows us to join the tables and match participants to their respective activities.

Note

A primary key uniquely identifies each record in a table, while a foreign key in one table refers to the primary key in another table, establishing a relationship between them. Here, ACTIVITYCODE in ACTIVITY is likely a primary key, and in PARTICIPANT, it's a foreign key.

Once the tables are joined, we need to filter the combined data according to the given conditions. The problem specifies two criteria for the activities:

  • The ACTIVITYNAME must contain the word 'bag'. This requires a pattern-matching operator, LIKE, combined with wildcard characters. The % wildcard matches any sequence of zero or more characters, so '%bag%' will find 'Hopping bag', 'Bean bag', or any other activity name that includes 'bag'.
  • The POINTS for the activity must be greater than 250. This is a straightforward numerical comparison using the > operator.

Both these conditions must be true for an activity to be included in the result, so they will be combined using the AND logical operator in the WHERE clause. Finally, we select only the NAME from the PARTICIPANT table and the ACTIVITYCODE and ACTIVITYNAME from the ACTIVITY table, as requested.

The SQL command to achieve this is:

SELECT P.NAME, A.ACTIVITYCODE, A.ACTIVITYNAME
FROM PARTICIPANT AS P
JOIN ACTIVITY AS A ON P.ACTIVITYCODE = A.ACTIVITYCODE
WHERE A.ACTIVITYNAME LIKE '%bag%' AND A.POINTS > 250;
``` …

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.