Click to See Complete Forum and Search --> : DELETE FROM table....


towerboy
07-06-2007, 08:28 PM
Hi,

What I am trying to do is delete a field that does not have a digit in it. This is what I have so far:
$sql = "DELETE FROM table WHERE LENGTH(field1) > 9 AND (user_id) > 2";

How do I DELETE a row that does not have a digit in it? If I were to make up a query to explain the concept further, it would look like this:
$sql = "DELETE FROM table WHERE LENGTH(field1) > 9 AND (user_id) > 2 AND DOES NOT CONTAIN 0-9";

bubbisthedog
07-09-2007, 03:47 PM
Untested:

AND [field name] NOT BETWEEN 0 AND 9

bubbisthedog
07-09-2007, 04:37 PM
I think I misinterpreted what you were asking, so you may want to ignore my previous post.

One approach would be to

1) use a SELECT statement:

select [unique ID field for table], [field to test for 0-9]
from table
where length(field1) > 9 and (user_id) > 2

2) use PHP to determine if [field to test for 0-9] contains a number
3) if [field to test for 0-9] contains a number, execute a DELETE statement:

delete from table where [unique ID field for table] = [unique ID field value]

I'm not sure if there's a more efficient way of doing that in SQL, to be honest.