Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    144

    Unanswered: 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.

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT username
         , CASE WHEN show_name = 'false'
                THEN name
                ELSE NULL END    AS name
         , show_name
      FROM daTable
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •