robert_gsfame Posted April 26, 2010 Share Posted April 26, 2010 I have query like this SELECT * FROM table1 WHERE folder='' the problem is no result appear when using that query, then i change to folder is NULL and it works.. What is the different between those two ??? if i want to have any records where folder is empty then which one should i use NULL or ''??? Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 26, 2010 Share Posted April 26, 2010 NULL means no value assigned. '' is an assignment. You probably want: WHERE folder IS NULL OR folder = '' Use NULL where nothing has been assigned to it. Don't assign '' (although most php I've seen assigns '' when the variable is NULL). If you want to clear a value use SET folder=NULL. I actually tried to make that coherent. Essentially what I am trying to say: $sql="UPDATE folder_table SET (folder='$folder')" If $folder=NULL in PHP then SQL is going to set the field as '' because the variable is surrounded by ticks. Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted April 27, 2010 Author Share Posted April 27, 2010 I try folder=NULL OR folder='' but still i found wrong records shown up.... Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 27, 2010 Share Posted April 27, 2010 WHERE folder = NULL will never be true. Because NULL means unknown, nothing is equal to it including another NULL. You have to use WHERE folder IS NULL to find rows that have a NULL value in the folder column. Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 27, 2010 Share Posted April 27, 2010 WHERE folder IS NULL OR folder = '' Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 27, 2010 Share Posted April 27, 2010 or even WHERE IFNULL(folder, '') = '' Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 27, 2010 Share Posted April 27, 2010 but not WHERE folder IN(NULL, '') Quote Link to comment Share on other sites More sharing options...
fenway Posted April 27, 2010 Share Posted April 27, 2010 but not WHERE folder IN(NULL, '') I've always HATED that. Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted April 27, 2010 Author Share Posted April 27, 2010 i rather set everything to blank '' Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 27, 2010 Share Posted April 27, 2010 but not WHERE folder IN(NULL, '') I've always HATED that. WHERE / IN in general? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 28, 2010 Share Posted April 28, 2010 No, the fact that the optimizer is dumb about explicit nulls. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.