What is the difference between the below queries & how it works?
SELECT * FROM some_table WHERE col IS NOT NULL
&
SELECT * FROM some_table WHERE col <> ''
Regards, Mubarak
NULL or Empty String: Which One to Use An empty string is a string instance of zero length. However, a NULL has no value at all. We can use a test database and apply the knowledge in the production environment to understand the concept better.
Learn MySQL from scratch for Data Science and Analytics In innoDB, NULL occupies less space as compared to empty string. Also, the NULL length is null while length of the empty string is 0. From the above output it is clear that the length of the empty string is 1. The above output means that count is 0 for null value.
An empty string is a String object with an assigned value, but its length is equal to zero. A null string has no value at all. A blank String contains only whitespaces, are is neither empty nor null , since it does have an assigned value, and isn't of 0 length.
In PHP, the empty string equals to a NULL value, but in MySQL, the case is the different i.e. empty string is not equal to NULL value.
The NULL
is special data type, it means absence of value.
An empty string on the other hand means a string or value which is empty.
Both are different.
For example, if you have name
field in table and by default you have set it to NULL
. When no value is specified for it, it will be NULL
but if you specify a real name or an empty string, it won't be NULL
then, it will contain an empty string instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With