Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove all NULL valued rows from table?

My sql query working fine but i have another issue some rows in my table have NULL values. i want to remove all NULL valued rows. Any recommendations?

like image 945
ali Avatar asked Sep 22 '17 10:09

ali


2 Answers

Delete statement should work

DELETE FROM your_table 
WHERE your_column IS NULL;

In case of multi column NULL check, I suggest using COALESCE

DELETE FROM your_table 
WHERE COALESCE (your_column1, your_column2, your_column3 ) IS NULL;
like image 135
SriniV Avatar answered Sep 22 '22 06:09

SriniV


If you want to delete a row where all columns values are null then use following query to delete:

    DELETE FROM your_table 
    where your_column1 IS NULL 
    AND your_column2 IS NULL 
    AND your_column3 IS NUL;

But if you want to delete a row where any column value is null then use following query to delete:

    DELETE FROM your_table 
    where your_column1 IS NULL 
    OR your_column2 IS NULL 
    OR your_column3 IS NUL;
like image 30
Rakib Avatar answered Sep 18 '22 06:09

Rakib