-1

How do I delete all rows that have a field called A that are blank.

Lets say I have a table that looks like the following.

|ID   |A   |B   |C
|1    |Data|Data|Data
|2    |    |Data|Data
|3    |Data|    |Data
|4    |    |    | 

So in the above example row 2 and 4 would be removed because there isn't anything stored in them?

How can I do this I'm doing I'm thinking something along the lines of the following.

Okay setup another table and tried the following.

DELETE FROM `table` WHERE `A`= ''

Is that that correct?

UPDATE

Okay setup another table and tried the following.

DELETE FROM `table` WHERE `A`= ''

Works as expected. I didn't want to do it a good table in case I borked anything

4

3 回答 3

3

It's hard to tell from what you provided because ...blank... can be interpreted in various ways but may be you are looking for something like this

DELETE 
  FROM Table1
 WHERE CHAR_LENGTH(COALESCE(TRIM(A), '')) = 0

What it does it deletes all rows that have in column A

  1. NULL values
  2. empty string values
  3. values that consist of only spaces

Here is SQLFiddle demo

于 2013-08-14T04:22:35.933 回答
2

You can use both

DELETE FROM `table` WHERE A = '';

or

DELETE FROM `table` WHERE A IS NULL;
于 2013-08-14T04:17:38.113 回答
0
DELETE FROM TABLENAME
WHERE A IS NULL OR TRIM(A) = '';
于 2013-08-14T04:37:13.330 回答