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 : (ii) To display Names of Participants, Activity Code, Activity Name in alphabetic ascending order of names of participants.

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 sorted alphabetically by participant name, you need to join the PARTICIPANT and ACTIVITY tables on the common ACTIVITYCODE field, then use an ORDER BY clause on the NAME column.

The question asks you to retrieve data from two related tables — PARTICIPANT and ACTIVITY — and present it in a specific sorted order. This is a classic example of a relational database query where information is spread across multiple tables and must be brought together using a join.

Let’s first understand what each table holds. The PARTICIPANT table stores details about each participant: their admission number (ADMNO), name (NAME), house (HOUSE), and the activity they are registered for (ACTIVITYCODE). The ACTIVITY table stores the activity code (ACTIVITYCODE), the full activity name (ACTIVITYNAME), and the points awarded for that activity (POINTS). Notice that ACTIVITYCODE appears in both tables — it is the link that connects a participant to the activity they have chosen.

The requirement is to display three columns: the participant’s name (from PARTICIPANT), the activity code (from PARTICIPANT), and the activity name (from ACTIVITY). The rows must be arranged in alphabetical order of participant names.

To combine the two tables, you use a JOIN operation. The most natural join here is an INNER JOIN, because you only want participants who have a matching activity in the ACTIVITY table (and every participant in the sample data does have a valid ACTIVITYCODE). The join condition is that the ACTIVITYCODE in PARTICIPANT equals the ACTIVITYCODE in ACTIVITY.

Once the tables are joined, you select the required columns: PARTICIPANT.NAME, PARTICIPANT.ACTIVITYCODE, and ACTIVITY.ACTIVITYNAME. Finally, you sort the result set using ORDER BY PARTICIPANT.NAME ASC (ascending is the default, so you can simply write ORDER BY NAME).

Note

In SQL, when column names are unique across the joined tables, you can omit the table prefix. Here, NAME and ACTIVITYCODE appear only in PARTICIPANT, and ACTIVITYNAME appears only in ACTIVITY, so you can write just NAME, ACTIVITYCODE, and ACTIVITYNAME without ambiguity. However, using table prefixes (like PARTICIPANT.NAME) is good practice for clarity.

The complete SQL command would be:

SELECT PARTICIPANT.NAME, PARTICIPANT.ACTIVITYCODE, ACTIVITY.ACTIVITYNAME
FROM PARTICIPANT …

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.