How do I delete blank rows in Mysql?

前端 未结 5 1139
忘了有多久
忘了有多久 2021-02-07 18:30

I do have a table with more than 100000 data elements, but there are almost 350 blank rows within. How do I delete this blank rows using phpmyadmin? Manually deleting is a tedio

5条回答
  •  庸人自扰
    2021-02-07 19:06

    I have a PHP script that automatically removes empty rows based on column data types.

    That allows me to define "emptiness" differently for different column types.

    e.g.

    table
    first_name (varchar) | last_name (varchar) | some_qty ( int ) | other_qty (decimal)
    
    DELETE FROM `table` WHERE
    (`first_name` IS NULL OR `first_name` = '')
    AND
    (`last_name` IS NULL OR `last_name` = '')
    AND
    (`some_qty` IS NULL OR `some_qty` = 0)
    AND
    (`other_qty` IS NULL OR `other_qty` = 0)
    

    Since "0" values are meaningless in my system, I count them as empty. But I found out that if you do (first_name = 0) then you will always get true, because strings always == 0 in MySQL. So I tailor the definition of "empty" to the data type.

提交回复
热议问题