7

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?

4
  • you can use where is not null Commented Sep 22, 2017 at 10:42
  • 2
    Are you sure you want to delete them from the table? Commented Sep 22, 2017 at 10:42
  • In your other question you're using SQL-Server. Why have you tagged this question for MySQL? Don't you understand the difference? Commented Sep 22, 2017 at 10:44
  • Every column in your table is NULLable, so you could technically leave the NULLvalued rows in place, and simply filter them out when you do a SELECT? Commented Sep 22, 2017 at 10:52

3 Answers 3

17

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;
Sign up to request clarification or add additional context in comments.

1 Comment

And, if you want to remove every row which contains a NULL anywhere, then you would simply extend the above: DELETE FROM your_table WHERE your_column1 IS NULL OR your_column2 IS NULL OR ...
4

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;

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.