Knowee
Questions
Features
Study Tools

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.

Question

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.

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

Solution

Here is the SQL query you asked for:

SELECT contact_number 
FROM building 
WHERE building_type_id IN (
    SELECT building_type_id 
    FROM building_type 
    WHERE building_type_name = 'Police Station'
) 
ORDER BY contact_number ASC;

Here's how it works:

  1. The subquery SELECT building_type_id FROM building_type WHERE building_type_name = 'Police Station' selects the building_type_id of the building type named 'Police Station'.

  2. The main query SELECT contact_number FROM building WHERE building_type_id IN (...) ORDER BY contact_number ASC selects the contact_number from the building table where the building_type_id matches the one we found in the subquery. The ORDER BY contact_number ASC at the end sorts the results in ascending order based on the contact_number.

This problem has been solved

Similar Questions

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.Sample output:SubmitSaveExecutePrevious Submission

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 the owner_name and contact_number of all building, Display the records in ascending order based on owner_name.Note:1. Display only the column named ‘owner_name’ and ‘contact_number’ present in the building table.2. Order by is mandatory

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.

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.

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.