IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New ! is a Logical Not operation
From a reference: Logical NOT. Evaluates to 1 if the operand is 0, to 0 if the operand is non-zero.

As for Null, the ANSI standard is that any operation on NULL (other than one in which NULL is being tested for explicitly - i.e. NOT NULL) will return false. So if you did something like:

WHERE (Name = NULL)

The statement evaluates false no matter what the value of name. In the case of !NULL, you are trying a logical comparison operation on a NULL value - which always returns false.

[edit add:] Or you could think of the operation as:

WHERE (Name != 0)

Expand Edited by ChrisR July 14, 2003, 01:53:33 PM EDT
New Gah, this is ugly
If 'name' is a varchar, SELECT * FROM customers WHERE name != 0 returns all the rows where 'name' starts with a number. SELECT * FROM customers WHERE name = 0 returns all the rows where 'name' starts with a letter.
===

Implicitly condoning stupidity since 2001.
New Best Guess
If 'name' is a varchar, SELECT * FROM customers WHERE name != 0 returns all the rows where 'name' starts with a number. SELECT * FROM customers WHERE name = 0 returns all the rows where 'name' starts with a letter.

Do you have any entries for 'name' that start with 0 and then letters? If my reading of this is right that will be returned by the second query not the first.

I think what is happening is that MySQL is converting 'name' to a number then doing the comparison. Anything that starts with a number converts to a number other then 0, anything that doesn't start with a number is being converted to 0.

If my reading of the manual is correct, SELECT * FROM customers WHERE !name should return rows where name when converted to a number evaluates to 0 and nothing else. But I could easily be way off. In any case, as a statement it doesn't make much sense. Your applying a logical operator to a character field.

I don't know how this would work in MySQL, but one clever way of doing what you want in MS SQL is SELECT * FROM customer WHERE len(' ' + name) = 1. That works because string + NULL = string and string + empty string = string.

Jay
New Was reusing syntax from other languages
On a bigint not null field it functioned as I expected, and I didn't consider that a varchar would be completely different. Correct syntax for what I wanted is WHERE name = '' OR name IS NULL.
===

Implicitly condoning stupidity since 2001.
New I've found SQL tends to be explicit.
Which removes unpleasant surprises like the one you were expecting. Hence the IS NULL clause.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Yes I always thought 'INSERT INTO' sounded naughty...
John. Busy lad.
New Bad! Bad Merkat! :-)

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

     MySQL syntax question - (drewk) - (9)
         ! is a Logical Not operation - (ChrisR) - (6)
             Gah, this is ugly - (drewk) - (5)
                 Best Guess - (JayMehaffey) - (4)
                     Was reusing syntax from other languages - (drewk) - (3)
                         I've found SQL tends to be explicit. - (static) - (2)
                             Yes I always thought 'INSERT INTO' sounded naughty... -NT - (Meerkat) - (1)
                                 Bad! Bad Merkat! :-) -NT - (static)
         What SQL dialect izzat? '!' for 'not' is usually C, not SQL. -NT - (CRConrad)
         pre-de-null - (tablizer)

Whenever someone says, "Show, don't tell," aren't they violating that exact rule?
49 ms