MySQL: NULL and ''

  • cancer10
  • Proficient
  • Proficient
  • cancer10
  • Posts: 268

Post 3+ Months Ago

Hi,

Is there any difference between, NULL and ''?

For example, consider this query


Code: [ Select ]
select * from employees where username is null



and

Code: [ Select ]
select * from employees where username = ''


Please explain the diff.


Thanx
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

NULL and the empty string are two completely different values and are treated as such by MySQL. In a nutshell, NULL means that no value has been entered into the field, but the empty string is still considered to be a value, even though the length of the string is zero.

Quote:
The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same thing as an empty string ''.


http://dev.mysql.com/doc/refman/5.0/en/ ... -null.html
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

http://dev.mysql.com/doc/refman/5.0/en/ ... -null.html
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

spork: 1
joebert: 0
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I noticed with MySQL 5+ if you do not make your text field default to NULL and then you try to insert a query without giving an empty string it will get mad and just not insert data.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

That's the expected behavior for "NOT NULL" being specified for a column PH. I believe you can get around that by also specifying a DEFAULT for the column. :)

Quote:
spork: 1
joebert: 0


My link leads to yours at the end of it, meaning my answer is actually two answers. :D

spork: 1
joebert: 2
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

I like the abbreviation you game me... "PH".

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 168 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.