Skip to content
Question 81 of 95

Q.Write SQL queries for

(a) to
(d) based on the tables PASSENGER and FLIGHT given below: Table: PASSENGER PNO NAME GENDER FNO 1001 Suresh Male F101 1002 Anita Female F104 1003 Harjas Male F102 1004 Nita Female F103 Table: FLIGHT FNO START END F_DATE FARE F101 MUMBAI CHENNAI 2021-12-25 4500 F102 MUMBAI BENGALURU 2021-11-20 4000 F103 DELHI CHENNAI 2021-12-10 5500 F104 KOLKATA MUMBAI 2021-12-20 4500 F105 DELHI BENGALURU 2021-01-15 5000
(a) Write a query to change the fare to 6000 of the flight whose FNO is F104.
(b) Write a query to display the total number of MALE and FEMALE PASSENGERS.
(c) Write a query to display the NAME, corresponding FARE and F_DATE of all PASSENGERS who have a flight to START from DELHI.
(d) Write a query to delete the records of flights which end at Mumbai.
Uttarakhand UbseCBSE Class XII Board 2022Subjective· 4mImportance★★★★★
85% · 81/95 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 →

Four SQL queries: (a) UPDATE to change a fare, (b) GROUP BY to count passengers by gender, (c) JOIN to display passenger details with flight information filtered by start city, and (d) DELETE to remove flight records ending at Mumbai.

The question asks you to manipulate and retrieve data from two related tables—PASSENGER and FLIGHT—using SQL. The relationship is straightforward: each passenger record contains a foreign key FNO that links to a flight in the FLIGHT table. Understanding this connection is essential because some queries require you to pull information from both tables simultaneously.

Let's work through each part, thinking about what the database needs to do.

(a) Changing the fare for flight F104

You need to modify an existing record. The UPDATE statement is designed for this: it targets a specific table, sets new values for one or more columns, and uses a WHERE clause to identify which row(s) to change. Here, you want to change the FARE column in the FLIGHT table where FNO equals F104.

UPDATE FLIGHT
SET FARE = 6000
WHERE FNO = 'F104';

The WHERE clause is crucial—without it, every flight's fare would be set to 6000. Always specify the condition that isolates the row you want to update.

(b) Counting passengers by gender

This is a classic aggregation problem. You want to count how many passengers fall into each gender category. The COUNT function tallies rows, and GROUP BY splits the result set into groups—one for each distinct value of GENDER. The query scans the PASSENGER table, groups rows by MALE and FEMALE, and counts how many are in each group.

SELECT GENDER, COUNT(*) AS TOTAL
FROM PASSENGER
GROUP BY GENDER;

The result will show two rows: one for MALE (with a count of 2) and one for FEMALE (also 2). The alias TOTAL makes the output column name clearer, though it's optional.

(c) Displaying passenger details for flights starting from Delhi

Now you need information from both tables. A passenger's name is in PASSENGER, but the fare and flight date are in FLIGHT. The link is FNO. An INNER JOIN combines rows from both tables where the FNO values match. Then you filter for flights where START equals 'DELHI'.

SELECT P.NAME, F.FARE, F.F_DATE
FROM PASSENGER P
JOIN FLIGHT F ON P.FNO = F.FNO
WHERE F.START = 'DELHI';

The aliases P and F make the query more readable. This will return Nita (who is on F103, Delhi to Chennai) with fare 5500 and date 2021-12-10. Notice that Harjas, though male, is on F102 (Mumbai to Bengaluru), so he doesn't appear in the result.

Note

The JOIN condition P.FNO = F.FNO is what stitches the two tables together. Without it, you'd get a Cartesian product—every passenger paired with every flight, which is meaningless here.

(d) Deleting flights that end at Mumbai …

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.