selecting form a mysql query where the string field is empty?

Discussion in 'MySQL' started by mahmood, Apr 14, 2006.

  1. #1
    I am trying to select rows from a mysql table where some fields are empty but it returns nothing.

    Say I have a string field in my table which is empty, the following query doesn't work as expected:
    
    SELECT * FROM myTable WHERE `Field1`=''
    
    PHP:
    How do I resolve it?
     
    mahmood, Apr 14, 2006 IP
    signorm68 likes this.
  2. Seiya

    Seiya Peon

    Messages:
    4,666
    Likes Received:
    404
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try

    SELECT * FROM myTable WHERE `Field1` LIKE '_________' 
    PHP:
    __ is a empty space
     
    Seiya, Apr 15, 2006 IP
  3. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #3
    The field may also be null so do something like
    
    SELECT * FROM myTable WHERE `Field1`='' or `Field1`is null
    
    Code (sql):
     
    dct, Apr 15, 2006 IP
  4. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for replies
    That "IS NULL" worked for me but I couldn't get "LIKE '_______'" working.
     
    mahmood, Apr 15, 2006 IP