Using Aliases

Say I have two tables, a contact_list (name, phone, alt_phone) and a scrub_list (scrub_num), I want to select the name and one of the phone num fields, alt_phone if not null, phone otherwise, then make sure it isn't on the scrub list. Is there a way to use an alias similar to the following (I know the following doesn't work)
SELECT name,
IF(alt_phone IS NOT NULL, alt_phone, phone) AS phone_num
FROM contact_list
LEFT JOIN scrub_list ON scrub_num = phone_num
WHERE scrub_num IS NULL

Thanks, Jesse
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!