Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I create a list of emails from first name, last name and city?

To clarify the question:
I have a table with customers which includes the first_name and last_name and the address_id. Now I have to create a list of new emails which are made of the first name and last name and the city:
firstname.lastname@city.com
I am using the sakila database btw if that is of any help
Could anybody explain to me, how I can accomplish this?
Thanks in advance!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The customer table has the first and last name, but not the city.
It has an address_id though, so we can join to the address table.

The address table doesn’t have the city name either, but it has a city_id.
So we join the city table to the address table.

Now with the required parts available, the new email can be constructed.

select replace(
          lower(
             concat(cust.first_name, '.', cust.last_name, '@', city.city, '.com')
          ), ' ', '_') as new_email
from customer cust
join address addr
  on addr.address_id = cust.address_id
join city
  on city.city_id = addr.city_id
order by new_email;

Some cities have spaces, so they were replaced.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading