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.
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.3. Order by is mandatory.4. Compare your executed result with the sample output given below.
Solution
Here is the SQL query you need to write to get the desired output:
SELECT contact_number
FROM building
WHERE building_type_id IN (
SELECT id
FROM building_type
WHERE name = 'Police Station'
)
ORDER BY contact_number ASC;
Here is the step by step explanation:
-
SELECT contact_number FROM building: This part of the query selects thecontact_numbercolumn from thebuildingtable. -
WHERE building_type_id IN (SELECT id FROM building_type WHERE name = 'Police Station'): This
Similar Questions
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.
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 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 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:
Write a query to display the name of all building types that ends with letter 'l'. Display the records in ascending order based on name.Note:1. Display only the name of building types that ends with L from building_type table.2. Order by is mandatory3. 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.