Write a query to display the details of the buildings whose owner name is Nicholas and 'Muzzammil'. Display the records sorted in ascending order based on the owner name and then by id.Note:1. Display only the details of the buildings whose owner name is Nicholas and Muzzammil.2. Use UNION3. Order by is mandatory. 4. Compare your executed result
Question
Write a query to display the details of the buildings whose owner name is Nicholas and 'Muzzammil'. Display the records sorted in ascending order based on the owner name and then by id.Note:1. Display only the details of the buildings whose owner name is Nicholas and Muzzammil.2. Use UNION3. Order by is mandatory. 4. Compare your executed result
Solution
Assuming you are using SQL, the query would look something like this:
(SELECT * FROM buildings WHERE owner_name = 'Nicholas')
UNION
(SELECT * FROM buildings WHERE owner_name = 'Muzzammil')
ORDER BY owner_name ASC, id ASC;
Here's the step by step breakdown:
-
SELECT * FROM buildings WHERE owner_name = 'Nicholas'- This part of the query selects all columns from thebuildingstable where theowner_nameis 'Nicholas'. -
UNION- This keyword is used to combine the result-set of two or more SELECT statements. It removes duplicate rows between the various SELECT statements. Each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types and they must be in the same order. -
SELECT * FROM buildings WHERE owner_name = 'Muzzammil'- This part of the query selects all columns from thebuildingstable where theowner_nameis 'Muzzammil'. -
ORDER BY owner_name ASC, id ASC- This part of the query sorts the result-set in ascending order byowner_nameand then byid. Ifowner_nameis the same for two rows, then it will sort byid.
Please replace buildings, owner_name, and id with your actual table name and column names.
Similar Questions
Write a query to display all the details of the buildings whose owner name contains 'di' in ascending order based on the owner name of the building.Note:1. Display all the columns from the building table whose owner_name contains “di” from building table.2. Order by is mandatory3. Compare your executed result with the sample output given below.
Write a query to display the entire details of the 'building' whose owner_name starts with the letter 'M', Display the records in ascending order based on their owner_name.Note:1. Display all the columns present in the building table.2. Specify the condition and retrieve the correct rows in the result(condition need to be specified on owner_name column).3. You can compare your executed result with the sample output given below.4. Order by is mandatorySample 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 owner name and the length of the owner's name of the buildings. Display the records in ascending order based on owner name. Give an alias as name_length to the length of the owner names.Use the inbuilt function length().Note:1. Display only the owner name and length of the owner_name from building table.2. Specify the alias name without any mistake.3. Order by is mandatory4. Compare your executed result with the sample output given below.Sample output:[only few records shown here]
Write a query to display the entire details of the building whose building_type_id is 2, sorted by owner_name in ascending order.Note:1. Display all the columns present in the building table.2. Specify the condition and retrieve the correct rows in the result(condition need to be specified on building_type_id column).3. You can compare your executed result with the sample output given below.4. Order by is mandatorySample output:
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.