Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete rows conditionally

Tags:

sql

I have a dataset with over 100,000 rows, over 100 columns and where some values are NULL. Now I want to remove all the rows which contain NULL values.

Can anybody suggest the sql command for it?

like image 613
Beta Avatar asked Dec 13 '22 14:12

Beta


1 Answers

With the little information you've provided:

DELETE FROM table WHERE colA IS NULL OR colB is NULL

Add further conditions for each column that you want to check.

Change OR to AND if you only want to delete rows where all of the columns are NULL.

It's fairly easy to generate the SQL for this using a query on user_tab_columns if you don't want to type it out by hand.

like image 114
Dave Costa Avatar answered Jan 03 '23 19:01

Dave Costa