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!
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.
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.
Try this
DELETE FROM user WHERE username IS NULL;
or
DELETE FROM user WHERE username = '';
Problems with NULL Values
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 = "";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With