MySQL mySQL查询删除列中的空记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18962596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mySQL Query Remove Null Records in Column
提问by Michael Falciglia
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?
我有一个很大的 mySQL 数据库,我想删除某个列中的每条空记录,而不是空记录。为此编写 SQL 查询的最佳方法是什么?
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.
但它没有删除任何东西。该列中有 44,000 条记录,其中几乎 80% 为空。
回答by Matthew
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
DELETE 语法的 MySQL 页面链接: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:
如果该列不是NULL
但只是空白,则需要执行以下操作:
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
根据您还在评论中提供的信息,这些值可能被加载为空 ( ''
) 而不是NULL
:http: //dev.mysql.com/doc/refman/5.7/en/problems-with-null.html
The second query should work.
第二个查询应该可以工作。
回答by juergen d
delete from your_table
where certain_column is null
回答by Purple
DELETE from `<tablename>`
WHERE `<columnname>` is null
回答by php
delete from table_name where column=''
回答by Ahsan Raza
delete from table_name where column_name is null; this query will definitely work for you.
从 table_name 中删除,其中 column_name 为空;这个查询肯定对你有用。
回答by Nevermore
Don't worry about count of data. Mysql can handle it. Just write:
不要担心数据的数量。Mysql 可以处理它。写就好了:
DELETE FROM `Businesses` WHERE `WEBADDRESS` = '';