1

Hello i am trying to count tracking numbers with non null non empty string in mysql

i see that count won't include null values. But is there a way to make it not include '' empty strings as well?

Thank you.

-Brendon

1 Answer 1

2

Try this, it will skip both NULL (which count doesn't count anyway) as well as empty string:

SELECT COUNT(*)
FROM TABLE
WHERE column_name != '' and column_name IS NOT NULL
Sign up to request clarification or add additional context in comments.

3 Comments

mysql seems to count NULLs as well unless you specify COUNT(column_name) but yeah this query looks right!
COUNT() counts rows returned, so it should count if no rows return, so if you remove COUNT() and just call the query with * you should see how many rows return, this is the COUNT() result.
I also thought you needed a TRIM(column_name) just in case when column_name is ' ' but apparently, you don't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.