Question 30 of 32intermediate🔧 ApplyShort Answer1 mark

Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following: Display the name of the costliest car with fuel type “Petrol”.

Correct Answer

SELECT CarName FROM INVENTORY WHERE FuelType = 'Petrol' AND Price = (SELECT MAX(Price) FROM INVENTORY WHERE FuelType = 'Petrol');

Exercise: EXERCISE | Q: 8(c) | (Page 50)
For More Understanding

Explanation

This query displays the name of the costliest car with fuel type 'Petrol' from the INVENTORY table. The query uses a subquery to find the maximum price among all Petrol cars, then matches it with the main query to retrieve the corresponding CarName. The INVENTORY table contains attributes like CarName, Price, and FuelType as per the CARSHOWROOM database schema shown in Figure 9.2.

Solution Steps

  1. Step 1: Identify the table (INVENTORY) and required columns (CarName, Price, FuelType)

  2. Step 2: Filter records where FuelType = 'Petrol'

  3. Step 3: Find the maximum price among Petrol cars using MAX() aggregate function in a subquery

  4. Step 4: Match the maximum price with the main query to display the CarName