If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help writing a sql statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-11, 02:08
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
Help writing a sql statement

I have a table contain 3 fields (username,name,show_name). I want to select all records, but in case of show_name=false, 'name' field should be empty. I already write one with union, but i thought must be better way.
Reply With Quote
  #2 (permalink)  
Old 02-16-11, 03:11
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Show us what you already tried and we can point you in the right direction. Also what do you mean by show_name = false, is this stored as a string value? It would be best to also provide the table definition and some sample table entries.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 02-16-11, 04:03
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Code:
SELECT username
     , CASE WHEN show_name = 'false'
            THEN name
            ELSE NULL END    AS name
     , show_name
  FROM daTable
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On