I have a table like :
id | name1 | name2 | name3
1 | asa | NULL | das
2 | NULL | NULL | asas
I want to delete every row that has two or more time the NULL value (here, the one with id = 2)
I already did that with a small PHP script but i wonder if that can be done with a mysql query
I am new to mysql so i didn't try anything yet!
You will want to use a WHERE
clause with multiple filters, each one checking is the column is null
:
delete
from yourtable
where
(name1 is null and name2 is null) or
(name1 is null and name3 is null) or
(name2 is null and name3 is null) or
(name1 is null and name2 is null and name3 is null)
See SQL Fiddle with Demo
delete from table where
(name1 is null AND name2 is null) OR
(name2 is null AND name3 is null) OR
(name1 is null AND name3 is null) OR
(name1 is null AND name2 is null AND name3 is null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With