Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL/MySQL NOT NULL vs NOT EMPTY

Tags:

sql

null

mysql

I'd like to limit my query to show only rows where a certain field is not empty. I found this thread where someone posed the same question and was told to use IS NOT NULL. I tried that, but I'm still getting rows where the field is empty.

What is the correct way to do this? Is Null the same thing as Empty in SQL/MySQL?

My query, if you're interested is: SELECT * FROM records WHERE (party_zip='49080' OR party_zip='49078' OR party_zip='49284' ) AND partyfn IS NOT NULL

like image 1000
cream Avatar asked May 06 '13 07:05

cream


People also ask

Is not null and is not empty in MySQL?

The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value. mysql> SELECT * FROM ColumnValueNullDemo WHERE ColumnName IS NULL OR ColumnName = ' '; After executing the above query, the output obtained is.

Is not null or empty SQL?

The IS NOT NULL condition is used in SQL to test for a non-NULL value. It returns TRUE if a non-NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

What is difference between NULL and empty in MySQL?

Sometimes strings can be empty or NULL. The difference is that NULL is used to refer to nothing. However, an empty string is used to point to a unique string with zero length.

IS NOT NULL is not empty?

@NotNull: a constrained CharSequence, Collection, Map, or Array is valid as long as it's not null, but it can be empty. @NotEmpty: a constrained CharSequence, Collection, Map, or Array is valid as long as it's not null, and its size/length is greater than zero.


1 Answers

I got it by using AND (partyfn IS NOT NULL AND partyfn != '')

like image 165
cream Avatar answered Oct 07 '22 18:10

cream