Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL Query Remove Null Records in Column

Tags:

sql

mysql

I have a large mySQL database and I want to remove every record that is empty, not null in a certain column. What is the best way to do write a SQL query for this?

Currently I have tried:

 DELETE FROM Businesses WHERE WEBADDRESS IS NULL

But it did not delete anything. There are 44,000 records and almost 80% of them are null in that column.

like image 668
Michael Falciglia Avatar asked Sep 23 '13 15:09

Michael Falciglia


2 Answers

DELETE FROM myTable WHERE myColumn IS NULL

Link to MySQL page for DELETE syntax: http://dev.mysql.com/doc/refman/5.7/en/delete.html

IF the column is not NULL but just blank you would need to do something like:

DELETE FROM myTable WHERE myColumn = ''

Based on the information you also provided in the comments, the values are likely being loaded as empty ('') and not NULL: http://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html

The second query should work.

like image 64
Matthew Avatar answered Sep 23 '22 02:09

Matthew


delete from your_table
where certain_column is null
like image 20
juergen d Avatar answered Sep 24 '22 02:09

juergen d