MySQL – Delete Rows from Table where Column is NULL
To delete rows of a table where the value of a specific column is NULL in MySQL, use SQL DELETE statement with WHERE clause and the condition being the column value is NULL.
The following is a simple syntax of DELETE statement with WHERE clause to delete rows from table where there is NULL in the column.
</>
Copy
DELETE FROM table_name column_name IS NULL ;
where
- table_name is the table name from which we would like to delete the rows.
- column_name is the name of column whose value has to be checked if it is
NULL
.
Examples
In the following example, we will consider a table students
and remove the rows where there is NULL
in the name
field/column.
“students” table before DELETE
name rollno
Arjun 14
Manish 15
Vina 16
NULL 17
NULL 18
SQL Query
</>
Copy
DELETE FROM students WHERE name IS NULL;
Response
2 row(s) affected
“students” table after DELETE
name rollno
Arjun 14
Manish 15
Vina 16