List:General Discussion« Previous MessageNext Message »
From:Andy Wallace Date:February 5 2013 5:10pm
Subject:Re: SELECT subquery problem
View as plain text  

select last_name, first_name, phone, if(pub_email='Y',email,'')

FROM `mydatabasetable` 

WHERE `current_member` = "Y" AND `pub_name` =
"Y" ORDER BY last_name ASC

 The "IF" statement returns it's second
argument if the first evaluates to true, the third argument


On 02-05-2013 6:49am, cl wrote: 

> De-lurking
> I am trying to figure out how to return results from a query.
What I need to do is to return 4 columns from a database. This is
> SELECT last_name, first_name, phone, email FROM
`mydatabasetable` WHERE `current_member` = "Y" AND `pub_name` = "Y"
ORDER BY last_name ASC
> This works fine, as expected.
> But, I
want to only display the value in `email` if the value in another field,
`pub_email` = "Y" So, the resultant output would look like this, for
instance, if the value of `pub_email` ="N" for Mr. Wills:
> Jones
John 555-555-5555 johnjones@stripped
> Smith Jim 555-222-2222
> Wills Chill 555-111-1111
> Zorro Felicity
555-999-9999 felicityzorro@stripped
> Can't quite figure out how to
express this.
> TIA for your suggestions!
> -- MySQL General
Mailing List For list archives: To
SELECT subquery problemcl5 Feb
  • RE: SELECT subquery problemCarlos Eduardo Caldi5 Feb
    • RE: SELECT subquery problemcl6 Feb
  • Aw: SELECT subquery problemStefan Kuhn5 Feb
    • Re: SELECT subquery problemAndrew Moore5 Feb
  • Re: SELECT subquery problemAndy Wallace5 Feb