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

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

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

Solution 1

Sure, here is the SQL query you asked for:

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

Here's a step-by-step breakdown of the query:

  1. SELECT: This keyword is used to select data from a database.

  2. SUBSTRING(owner_name, 1, 3) AS name_code: The SUBSTRING function extracts a part of a string. Here, it's used to get the first 3 characters of the owner_name column. The AS keyword is used to rename the column in the output as name_code.

  3. contact_number: This is the second column that we want to display in the output.

  4. FROM buildings: This specifies the table from which to retrieve the data.

  5. ORDER BY owner_name ASC: This orders the output in ascending order (ASC) based on the owner_name column.

This problem has been solved

Solution 2

Sure, here is the SQL query you asked for:

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

Here's a step-by-step breakdown of the query:

  1. SELECT: This keyword is used to select data from a database.

  2. SUBSTRING(owner_name, 1, 3) AS name_code: The SUBSTRING function extracts a part of a string. Here, it's used to get the first 3 characters of the owner_name column. The AS keyword is used to rename the column in the output as name_code.

  3. contact_number: This is the second column that we want to display in the output.

  4. FROM buildings: This specifies the table from which to retrieve the data, which is buildings in this case.

  5. ORDER BY owner_name ASC: This is used to sort the results in ascending order (ASC) based on the owner_name column.

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

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().

Write a query to display the owner_name and contact_number of all building, Display the records in ascending order based on owner_name.

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.

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

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.