Write a query to display all the owner_name and concatenate contact_number and email with a hyphen(-) separated . Display the records in descending order based on owner_name . Give an alias name as 'contact_details'.Note:1. Display only the owner name and concatenate contact_number and email with – seperated from building table.2. Specify the alias name without any mistake.3. Order by is mandatory4. Use CONCAT function5. Compare your executed result with the sample output given below.
Question
Write a query to display all the owner_name and concatenate contact_number and email with a hyphen(-) separated . Display the records in descending order based on owner_name . Give an alias name as 'contact_details'.Note:1. Display only the owner name and concatenate contact_number and email with – seperated from building table.2. Specify the alias name without any mistake.3. Order by is mandatory4. Use CONCAT function5. Compare your executed result with the sample output given below.
Solution 1
Based on your instructions, here is the SQL query:
SELECT owner_name, CONCAT(contact_number, '-', email) AS 'contact_details'
FROM building
ORDER BY owner_name DESC;
This query does the following:
- Selects the
owner_namecolumn from thebuildingtable. - Concatenates the
contact_numberandemailcolumns with a hyphen (-) in between. This concatenated string is given the aliascontact_details. - Orders the resulting records in descending order based on the
owner_namecolumn.
Solution 2
Based on your instructions, here is the SQL query you need:
SELECT owner_name, CONCAT(contact_number, '-', email) AS 'contact_details'
FROM building
ORDER BY owner_name DESC;
Here's a step-by-step breakdown of the query:
-
SELECT owner_name, CONCAT(contact_number, '-', email) AS 'contact_details': This part of the query is selecting the columns you want to display. TheCONCATfunction is used to combine thecontact_numberandemailcolumns with a hyphen (-) in between. TheAS 'contact_details'part is giving this concatenated column an alias name of 'contact_details'. -
FROM building: This is specifying the table from which to select the data, in this case, the 'building' table. -
ORDER BY owner_name DESC;: This is ordering the results by theowner_namecolumn in descending order. TheDESCkeyword specifies descending order. If you wanted ascending order, you could useASCinstead.
Please replace building, owner_name, contact_number, and email with your actual table and column names if they are different.
Solution 3
Based on your instructions, here is the SQL query:
SELECT owner_name, CONCAT(contact_number, '-', email) AS 'contact_details'
FROM building
ORDER BY owner_name DESC;
This query does the following:
- Selects the
owner_namecolumn from thebuildingtable. - Concatenates the
contact_numberandemailcolumns with a hyphen (-) in between. This concatenated string is given the aliascontact_details. - Orders the resulting records in descending order based on the
owner_namecolumn.
Similar Questions
Write a query to display the owner_name and mail id in which the string should end before the '@' symbol. Display the details of the buildings which are having the email address and give an alias name as 'email_name' and display it in ascending order based on owner name.Note:1. Display only the owner name and mail id in which the string ends before the @ from building table.2. Specify the alias name without any mistake.3. Order by is mandatory4. Use SUBSTR function5. Compare your executed result with the sample output given below.Sample output:[only few records 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 first 3 characters of the owner_name and the contact_number of all buildings in ascending order based on the owner name of the building. Give an alias to the first 3 characters as 'name_code'.Note:1. Display only the first 3 characters of owner names and contact_number from building table.2. Specify the alias name without any mistake.3. Order by is mandatory.4. Use the inbuilt function lpad().5. 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 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]
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.