RE: SELECT subquery problem

2013-02-06 Thread cl
  You can do:
  
  
  SELECT last_name, first_name, phone, if(pub_email=Y,email,) as email
  FROM `mydatabasetable` WHERE `current_member` = Y AND `pub_name` = Y
  ORDER BY last_name ASC
  

Gracias, Carlos. This worked fine!

---Fritz


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



SELECT subquery problem

2013-02-05 Thread cl
De-lurking here.

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 easy:

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-   johnjo...@nowhere.com
Smith  Jim   555-222-   jimsm...@nothing.com
WillsChill  555-111-
Zorro  Felicity  555-999-  felicityzo...@madeup.com

Can't quite figure out how to express this.

TIA for your suggestions!


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: SELECT subquery problem

2013-02-05 Thread Andrew Moore
Try using a CASE construct in the select. Should work for this.

A


On Tue, Feb 5, 2013 at 3:25 PM, Stefan Kuhn stef...@web.de wrote:

 You cannot do this. A sql result alwas has the same number of columns in
 each row. You could have null or  in the column, though. This could be
 done via the if(,,)-statement of mysql or by using a union and two selects,
 one for pub_email=n and the other for the rest.


 Gesendet: Dienstag, 05. Februar 2013 um 15:49 Uhr
 Von: cl c...@nimbleeye.com
 An: mysql@lists.mysql.com
 Betreff: SELECT subquery problem
 De-lurking here.

 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 easy:

 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- johnjo...@nowhere.com
 Smith Jim 555-222- jimsm...@nothing.com
 Wills Chill 555-111-
 Zorro Felicity 555-999- felicityzo...@madeup.com

 Can't quite figure out how to express this.

 TIA for your suggestions!


 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe: http://lists.mysql.com/mysql[http://lists.mysql.com/mysql]




 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql




Aw: SELECT subquery problem

2013-02-05 Thread Stefan Kuhn
You cannot do this. A sql result alwas has the same number of columns in each 
row. You could have null or  in the column, though. This could be done via 
the if(,,)-statement of mysql or by using a union and two selects, one for 
pub_email=n and the other for the rest.


Gesendet: Dienstag, 05. Februar 2013 um 15:49 Uhr
Von: cl c...@nimbleeye.com
An: mysql@lists.mysql.com
Betreff: SELECT subquery problem
De-lurking here.

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 easy:

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- johnjo...@nowhere.com
Smith Jim 555-222- jimsm...@nothing.com
Wills Chill 555-111-
Zorro Felicity 555-999- felicityzo...@madeup.com

Can't quite figure out how to express this.

TIA for your suggestions!


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql[http://lists.mysql.com/mysql]




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql