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.
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:
-
The subquery
SELECT building_type_id FROM building_type WHERE building_type_name = 'Police Station'selects thebuilding_type_idof the building type named 'Police Station'. -
The main query
SELECT contact_number FROM building WHERE building_type_id IN (...) ORDER BY contact_number ASCselects thecontact_numberfrom thebuildingtable where thebuilding_type_idmatches the one we found in the subquery. TheORDER BY contact_number ASCat the end sorts the results in ascending order based on thecontact_number.
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.
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.