20

First of all thanks for your help. I do an learning SQL, so I need some help.

I have a Sqlite database in which some fields in a certain column contains nothing or string of spaces.

Please How do I delete the rows containing nothing (or string of spaces) from the database?

Thanks for your help.

4 Answers 4

41

Try this:

DELETE FROM myTable WHERE myColumn IS NULL OR trim(myColumn) = '';

The trim() is necessary so that strings containing just whitespace are collapsed to an empty string.

Sign up to request clarification or add additional context in comments.

3 Comments

Could you share your test data? That works fine for me with SQLite.
of course. But I have to send you the db via email because I am behind a firewall
sqlite kungfu plus one, it worked with DELETE FROM myTable WHERE myColumn IS null
4

Try this:

DELETE FROM tbl
WHERE
  (filed IS NULL OR filed  = '')

Multiple Column:

DELETE FROM tbl
WHERE
  (filed IS NULL OR filed  = '')
  AND (filed2 IS NULL OR filed2 = '')
  AND (filed3 IS NULL OR filed2 = '')

Comments

1

This answer will work for any SQL database:

DELETE FROM MY_TABLE
WHERE MY_COLUMN IS NULL
OR TRIM(MY_COLUMN) = ''

See this WHERE clause working in SQLFiddle

3 Comments

This doesn't detect the "string of spaces" case.
Nope, I've just tested with SQLite. A string of spaces does not match ''.
@GrahamBorland I just tested it too. and was surprised to find it needed the TRIM()... answer edited
1

DELETE FROM MY_TABLE WHERE MY_COLUMN IS NULL OR MY_COLUMN like ''

Comments

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.