9

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.

1
  • Fixed your question based on your comment. This is a much better SO question now, providing some information on what you have done and more context for people trying to help. Commented Sep 23, 2013 at 15:25

6 Answers 6

22
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.

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

5 Comments

I tried it, but it did not delete anything. There are 44,000 records and almost 80% of them are null in that column. Here is my query DELETE FROM Businesses WHERE WEBADDRESS IS NULL
Do you have a foreign key dependency on these records? Is there any error message? Is the column actually null or just blank?
I had a CSV file that has 19 columns, so I created a table and named each column like the CSV had them and made them all VARCHAR 255, then imported the CSV. The import was successful with no errors and I made no other changes to the table structure.
oh I see, null is different than being blank. I did not know that. I will try that now.
@OP the second query should work, MySQL should be importing these empty columns as '' unless you are specifying \N for the rows which should be null.
2
delete from your_table
where certain_column is null

Comments

1
DELETE from `<tablename>`
WHERE `<columnname>` is null

Comments

1
delete from table_name where column=''

Comments

0

Don't worry about count of data. Mysql can handle it. Just write:

 DELETE FROM `Businesses` WHERE `WEBADDRESS` = '';

Comments

-1

delete from table_name where column_name is null; this query will definitely work for you.

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.