QueryQ2Write a query to display the meter number,owner name,address and contact number of all the buldings. Display the record in ascending order based on owner name.Note:1. Display only the below 4 columns, i. meter number ii. owner name iii. address iv. contact number 2. Use Joins3. Tables involved building and meter4. Order by is mandatory.5. Compare your executed result with the sample output given below.Sample output: [Only few records are shown here]
Question
QueryQ2Write a query to display the meter number,owner name,address and contact number of all the buldings. Display the record in ascending order based on owner name.Note:1. Display only the below 4 columns, i. meter number ii. owner name iii. address iv. contact number 2. Use Joins3. Tables involved building and meter4. Order by is mandatory.5. Compare your executed result with the sample output given below.Sample output: [Only few records are shown here]
Solution
Here is a SQL query that should give you the desired output:
SELECT
meter.meter_number,
building.owner_name,
building.address,
building.contact_number
FROM
building
JOIN
meter ON building.building_id = meter.building_id
ORDER BY
building.owner_name ASC;
This query works as follows:
-
SELECT meter.meter_number, building.owner_name, building.address, building.contact_number: This line is selecting the four columns that you want to display. -
FROM building: This line is specifying the main table that we are selecting from, which is thebuildingtable. -
JOIN meter ON building.building_id = meter.building_id: This line is joining themetertable with thebuildingtable. TheONkeyword is used to specify the column upon which the tables should be joined. In this case, it's thebuilding_idcolumn. -
ORDER BY building.owner_name ASC: This line is ordering the output in ascending order by theowner_namecolumn in thebuildingtable. TheASCkeyword specifies that the sorting should be in ascending order. If you wanted to sort in descending order, you would use theDESCkeyword.
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.Sample output: [Only few records are shown here]
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 and address of the owner who paid second least fine total amount. If there are multiple records display in ascending order based on owner name.Note:1. Display only the below 3 columns, i. meter number ii. owner name iii. address with the condition who paid seocnd least fine total amount.2. Use Joins3. Tables involved are building, meter and bill4. Order by is mandatory.5. Compare your executed result with the sample output given below.Sample output:
Write a query to display the building owner name ,address and number of connections present in each building. Display the records in ascending order based on owner name.Give an alias name as connection_count.Note:1. Display only the building owner_name ,address and number of connections.2. Use Joins3. Tables involved building, building_type, meter4. Specify the alias name without any mistake.5. Order by is mandatory. 6. 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.
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.