remove all NULL valued rows from table?

Viewed 31665

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?

3 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;

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;

You could start by filtering out columns you don't need, want, or will not use.

SELECT column1, column2, column3
FROM table

Then to remove the null values from your queries, use the IS NOT NULL command. Remember, null values can also be zeros, depending on how your tables and the data formats have been set up. In the example below, assume column2 is a number format.

WHERE column1 IS NOT NULL AND column2 > 0 AND column3 IS NOT NULL
Related