List:General Discussion« Previous MessageNext Message »
From:Jon Stephens Date:November 17 2004 8:45pm
Subject:Re: IF() problem
View as plain text  
> Date: Wed, 17 Nov 2004 12:50:47 +0100
> To: mysql@stripped
> From: "Przemyslaw Popielarski" <przemyslaw.popielarski@stripped>
> Subject: IF() problem
> Message-ID: <419B4927.22428.248784F3@localhost>
> 
> select IF(BOOK1PL,BOOK1PL,BOOK1EN)
> from tBooksextra where ksi='id'
> 
> -> (content of BOOK1EN)
> 
> select BOOK1PL from tBooksextra 
> WHERE BOOK1PL IS NOT NULL
> AND  BOOK1PL!='' AND ksi='id'
> 
> -> (content of BOOK1PL).
> 
> Why didn't I get the content of BOOK1PL in 1st query?
> 
> (checked in 4.0.21 and 4.1.7)

Observe:

mysql> SELECT 'something' = 0, '' = 0;
+-----------------+--------+
| 'something' = 0 | '' = 0 |
+-----------------+--------+
|               1 |      1 |
+-----------------+--------+
1 row in set (0.02 sec)

*Any* string value evaluates as 0 (FALSE), not just the empty string.

You want "If BOOK1PL is not empty, return BOOK1PL, otherwise return 
BOOK1EN", correct?

Then try this instead:

SELECT IF(BOOK1PL <> '', BOOK1PL, BOOK1EN)
FROM tBooksextra WHERE ksi = 'id';

-- 
Jon Stephens, Technical Writer
MySQL AB   www.mysql.com
Office: +61 (07) 3388 2228
Are you MySQL certified?  www.mysql.com/certification
Thread
IF() problemPrzemyslaw Popielarski17 Nov
Re: IF() problemJon Stephens17 Nov
  • Re: IF() problemPrzemyslaw Popielarski18 Nov
Re: IF() problemJon Stephens18 Nov