Date: Wed, 17 Nov 2004 12:50:47 +0100 To: [EMAIL PROTECTED] From: "Przemyslaw Popielarski" <[EMAIL PROTECTED]> Subject: IF() problem Message-ID: <[EMAIL PROTECTED]>
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
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]