Take the 2-minute tour ×

I have a MySQL table that keeps details about people, for example:

  • Name
  • Address
  • WorkEmail
  • HomeEmail
  • Preferred Email ('WorkEmail' or 'HomeEmail')

I want to select their preferred email only. Is there a neat way to do this using SQL? or will I just need to do this after I pull out the data?

share|improve this question

5 Answers 5

up vote 5 down vote accepted

A simple case statement should do the trick:

    CASE WHEN PreferredEmail = 'WorkEmail' THEN WorkEmail ELSE HomeEmail END AS Email
share|improve this answer
Awesome! did the trick nicely. Cheers! I'm sorta still a bit of a noob when it comes to SQL –  Sam Williams Dec 30 '11 at 4:13
You're welcome! You could mark the answer as correct too... ;-) –  paulbailey Dec 30 '11 at 10:51
(Select WorkEmail from MyTable where preferredEmail = 'WorkEmail') 
(Select HomeEmail from MyTable where preferredEmail = 'HomeEmail') 
share|improve this answer

select IF(PreferredEmail = 'WorkEmail', WorkEmail, HomeEmail) AS Email

share|improve this answer

Why do you need a list of more than one email? If you are collecting multiple email address and you may at sometime want to collect more than one you could always create a secondary table that would associate the user with all of their possible email addresses and have a second third column that could be a flag to signify the Primary email.

Main Table

- Name
- Address

Email table

- Email address
- Primary

Then you could just do a query for where Primary is flagged and join to the other on the Unique ID.

share|improve this answer

This is a simple query:

SELECT PreferredEmail FROM people;
share|improve this answer
You seem to misunderstand the question. –  Karlson Dec 30 '11 at 5:13

Your Answer


