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
Question
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
Solution
It seems like you're asking for a SQL query. Here's how you can write it:
SELECT owner_name,
SUBSTRING_INDEX(mail_id, '@', 1) AS email_name
FROM buildings
WHERE mail_id IS NOT NULL
ORDER BY owner_name ASC;
Here's a step-by-step breakdown of the query:
-
SELECT owner_name, SUBSTRING_INDEX(mail_id, '@', 1) AS email_name: This part of the query is selecting theowner_nameand the part of themail_idbefore the '@' symbol. TheSUBSTRING_INDEXfunction is used to get the substring before the '@' symbol. -
FROM buildings: This part of the query specifies the table we are selecting the data from, which is thebuildingstable. -
WHERE mail_id IS NOT NULL: This part of the query is a condition that filters out the records wheremail_idis not present. -
ORDER BY owner_name ASC: This part of the query sorts the result in ascending order by theowner_name.
Please replace buildings, owner_name, and mail_id with your actual table and column names if they are different.
Similar Questions
Write a query to display the owner_name, address and contact_number of the buildings which does not have an email_address. Display the records in ascending order based on their owner_name.
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 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.
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 contact_number of all building, Display the records in ascending order based on owner_name.
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.