Knowee
Questions
Features
Study Tools

Write a query to display the meter_number of the building_type named 'College'. Display the records in ascending order based on their meter_number.Note:1. Display only the meter_number column present in the meter table where building_type name is ‘College’. Use subqueries to achieve this.2. Tables involved are building_type, building and meter.3. Order by is mandatory4. Compare your executed result with the sample output given below.

Question

Write a query to display the meter_number of the building_type named 'College'. Display the records in ascending order based on their meter_number.Note:1. Display only the meter_number column present in the meter table where building_type name is ‘College’. Use subqueries to achieve this.2. Tables involved are building_type, building and meter.3. Order by is mandatory4. Compare your executed result with the sample output given below.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Here is the SQL query you need:

SELECT meter_number 
FROM meter 
WHERE building_id IN (
    SELECT building_id 
    FROM building 
    WHERE building_type_id IN (
        SELECT building_type_id 
        FROM building_type 
        WHERE building_type_name = 'College'
    )
)
ORDER BY meter_number ASC;

This query works as follows:

  1. The innermost subquery selects the building_type_id from the building_type table where the building_type_name is 'College'.
  2. The next subquery selects the building_id from the building table where the building_type_id is in the list retrieved from the innermost subquery.
  3. The outermost query selects the meter_number from the meter table where the building_id is in the list retrieved from the second subquery.
  4. Finally, the results are ordered in ascending order by meter_number.

This problem has been solved

Solution 2

Here is the SQL query you asked for:

SELECT meter_number 
FROM meter 
WHERE building_id IN (
    SELECT building_id 
    FROM building 
    WHERE building_type_id IN (
        SELECT building_type_id 
        FROM building_type 
        WHERE building_type_name = 'College'
    )
)
ORDER BY meter_number ASC;

This query works as follows:

  1. The innermost subquery selects the building_type_id from the building_type table where the building_type_name is 'College'.
  2. The next subquery selects the building_id from the building table where the building_type_id is in the list retrieved from the first subquery.
  3. The outermost query selects the meter_number from the meter table where the building_id is in the list retrieved from the second subquery.
  4. Finally, the ORDER BY clause sorts the results in ascending order by meter_number.

This problem has been solved

Solution 3

Here is the SQL query you asked for:

SELECT meter_number 
FROM meter 
WHERE building_id IN (
    SELECT building_id 
    FROM building 
    WHERE building_type_id IN (
        SELECT building_type_id 
        FROM building_type 
        WHERE building_type_name = 'College'
    )
)
ORDER BY meter_number ASC;

This query works as follows:

  1. The innermost subquery selects the building_type_id from the building_type table where the building_type_name is 'College'.
  2. The next subquery selects the building_id from the building table where the building_type_id is in the list retrieved from the innermost subquery.
  3. The outermost query selects the meter_number from the meter table where the building_id is in the list retrieved from the second subquery.
  4. Finally, the results are ordered in ascending order by meter_number.

This problem has been solved

Similar Questions

Write a query to display the  meter number,owner name,address,contact number,building type name and connection name of all buildings.Display the records in ascending order based on building type name.Note:1. Display only the below 6 columns,     i. meter number     ii. owner name     iii. address     iv. contact number     v. building type name     vi. Connection name  2. Use Joins3. Tables involved building, meter, building_type, electricity_connection_type4. Order by is mandatory.5. Compare your executed result with the sample output given below.

Write a query to display all the contact number of the building_type named 'Police Station'. Display the records in ascending order based on the contact number.Note:1. Display only the contact_number column present in the building table where building_type name is ‘Police Station’. Use subqueries to achieve this.2. Tables involved are building_type and building.3. Order by is mandatory.4. Compare your executed result with the sample output given below.

Write a query to display all the 'bills' with 'meter' details. Display the records in ascending order based on meter number.Note:1. Display all the columns of bill and meter table2. Use Joins3. Tables involved bill and meter4. Order by is mandatory5. Compare your executed result with the sample output given below.

Write a query to get the owner_name from the building table who have consumed maximum total_units of current in a month. Display the records in ascending order based on their owner_name.Note:1. Display only the owner_name from the building table who have consumed maximum total_units of current in a month.2. Tables involved are building, meter and bill3. Order by is mandatory4. Compare your executed result with the sample output given below.

Write a query to display all the building details in which building_type named ‘Library’. Display the records in ascending order based on their owner_name.Note:1. Display all the column present in the building table where building_type name is ‘Library’. Use subqueries to achieve this.2. Tables involved are building_type and building3. Order by is mandatory.4. Compare your executed result with the sample output given below.Sample output:

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.