Knowee
Questions
Features
Study Tools

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]

Question

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]

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The language of the text is SQL (Structured Query Language), which is used for managing and manipulating databases. Here is the SQL query based on your requirements:

SELECT 
    SUBSTRING(owner_name, 1, 3) AS name_code, 
    contact_number 
FROM 
    buildings 
ORDER BY 
    owner_name ASC;

Please note that the SUBSTRING function is used to get the first 3 characters of the owner_name. The AS keyword is used to give an alias name_code to the new column. The ORDER BY clause is used to sort the results in ascending order by owner_name.

The LPAD function mentioned in the question is not used in this query because it is typically used to pad the left side of a string with a specific set of characters until the string reaches a certain length. In this case, we are not padding any strings, but rather truncating the owner_name to its first 3 characters.

This problem has been solved

Solution 2

The language of the text is SQL (Structured Query Language), which is used for managing and manipulating databases. Here is the SQL query based on your requirements:

SELECT 
    SUBSTRING(owner_name, 1, 3) AS name_code, 
    contact_number 
FROM 
    buildings 
ORDER BY 
    owner_name ASC;

This query will select the first 3 characters of the owner_name field (and give it an alias of name_code), and the contact_number field from the buildings table. The results will be ordered in ascending order by the owner_name field.

Please note that the SUBSTRING function is used to get the first 3 characters of the owner_name. The lpad() function mentioned in the question is not used because it is typically used to pad the left side of a string with a specific set of characters, which doesn't seem to be required based on the provided details.

This problem has been solved

Similar Questions

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'.

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 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 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]

1/3

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.