Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite: how to delete rows that contain null/empty strings

Tags:

sql

sqlite

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.

like image 894
Lisa Anne Avatar asked May 16 '13 12:05

Lisa Anne


2 Answers

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.

like image 117
Graham Borland Avatar answered Sep 16 '22 13:09

Graham Borland


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 = '')
like image 26
KF2 Avatar answered Sep 18 '22 13:09

KF2