Scott Noyes wrote:
I have a table like this :
name, email_1, email_2
and I want to display in a web page
name, email_1 if it exists, or email_2 if email_1 do NOT exist.
What if email_2 does not exist, either?
SELECT name, IF(email_1 IS NOT NULL AND email_1 != '', email_1,
email_2) AS email FROM theTable;
If "do NOT exist" means NULL, you can simply use COALESCE(), which returns
the first non-NULL item in the given list:
SELECT COALESCE(email_1, email_2, 'No address') as email FROM theTable;
On the other hand, if email_1 could be an empty string, then something like
Scott's suggestion is the way to go.
Michael
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]