Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Removing null value rows from table

Tags:

mysql

I have a table "user" with over 60 columns. One of the column's name is "username"

I want to remove the rows where the username field is empty or NULL

How can I do this?

Thank you!

like image 385
Achilles Avatar asked Feb 25 '14 07:02

Achilles


People also ask

How do I remove a row from a NULL value in MySQL?

Use the delete command to delete blank rows in MySQL. delete from yourTableName where yourColumnName=' ' OR yourColumnName IS NULL; The above syntax will delete blank rows as well as NULL row.

Which of the following would return the number of non NULL records in a table?

With SQL, how can you return the number of not null records in the “Persons” table? Explanation: COUNT(column_name) is used to count the number of rows of a table where column name is a column that does not allow NULL values.


2 Answers

Try this

DELETE FROM user WHERE username IS NULL;

or

DELETE FROM user WHERE username = '';

Problems with NULL Values

like image 85
Nagaraj S Avatar answered Sep 26 '22 03:09

Nagaraj S


If you want to delete all those rows containing username = NULL AND where username is empty string ("") as well

then

DELETE FROM table_name WHERE username IS NULL OR username = '';

It is advised to first do a SELECT query with same WHERE condition as that you are going to use in DELETE query to see which rows will be deleted:

SELECT * FROM table_name WHERE username IS  NULL OR username = "";
like image 25
Deepak Rai Avatar answered Sep 26 '22 03:09

Deepak Rai