Home > database >  Google Sheet Query: Why "!= ' '" doesn't work?
Google Sheet Query: Why "!= ' '" doesn't work?

Time:08-06

To select cells that are not empty, we have to use something like

SELECT * WHERE A IS NOT NULL

If I replace it with

   SELECT * WHERE A != ''

or

   SELECT * WHERE A != ' '

There will be no error but nothing is returned.

Why is this?

CodePudding user response:

when referring to a null cell try:

"where A <> ''"

enter image description here

or:

"where not A = ''"

enter image description here

or:

"where not A matches ''"

enter image description here

or:

"where not A matches '^$'"

enter image description here

or:

"where not A like ''"

enter image description here

but even yours:

"where A != ''"

enter image description here

and:

"where A is not null"

enter image description here

will work...

the real issue is the shabby query behavior when you got a mixed dataset (numeric plain text) and query makes the wrong assumption that you don't need the minority of the set:

enter image description here

where in such case you will need to force the formatting like:

=ARRAYFORMULA(QUERY(A:A&"", "where Col1 is not null", ))

enter image description here

notice the Col1 syntax

but there are cases when you need not to convert numeric values into plain text values so in such case it is better to use:

=FILTER(A:A, A:A<>"")

enter image description here

  • Related