0 not found in WHERE however value is 0

You are viewing an old version of this question. View the current version here.

TABLE DEFINITION CREATE TABLE `tblArtikelen` ( `ArtikelCode` int(10) NOT NULL DEFAULT 0, `ArtikelDesc` varchar(100) DEFAULT NULL, `ArtikelSoort` tinyint(3) unsigned DEFAULT NULL, `ArtikelBTWID` smallint(5) DEFAULT NULL, `ArtikelStandaardPrijs` decimal(19,4) DEFAULT NULL, `ArtikelFacturatieEenheid` varchar(10) DEFAULT NULL, `ArtikelGLAccountNumber` varchar(6) DEFAULT NULL, `ArtikelIsVoorraad` tinyint(1) NOT NULL, `ArtikelVVP` decimal(19,4) DEFAULT NULL, `ArtikelSKU` varchar(255) DEFAULT NULL, `ArtikelStandaardVerkoopPrijs` decimal(19,4) DEFAULT NULL, `ArtikelInVerkoop` tinyint(1) NOT NULL, `ArtikelPrintOpVerkoopPrijsLijst` tinyint(1) NOT NULL, PRIMARY KEY (`ArtikelCode`), KEY `ArtikelCode` (`ArtikelCode`), KEY `Eenheid` (`ArtikelFacturatieEenheid`), KEY `BTW-code` (`ArtikelBTWID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

TABLE CONTENT

  1. ArtikelCode, ArtikelDesc, ArtikelSoort, ArtikelBTWID, ArtikelStandaardPrijs, ArtikelFacturatieEenheid, ArtikelGLAccountNumber, ArtikelIsVoorraad, ArtikelVVP, ArtikelSKU, ArtikelStandaardVerkoopPrijs, ArtikelInVerkoop, ArtikelPrintOpVerkoopPrijsLijst '7', 'Kantoor artikelen', '2', '221', '0.0000', 'p/product', '432000', '0', NULL, NULL, NULL, '0', '0'

QUERY SELECT count(*) FROM `tblArtikelen` where `ArtikelCode` = 7 AND ArtikelIsVoorraad in (TRUE or FALSE or 1 or 0 or '0' or '1');

EXPECT value of select = 1 ACTUAL value of select = 0

Can someone explain why this is happening?

Kind regards, Peter

Answer Answered by Ian Gilfillan in this comment.

The value of the expression (1 OR 0) is 1, which does not match your row.

The IN operator is basically a shorthand for a number of ORs using comma delimitation. I think what you are intending to do is something like:

SELECT count(*) FROM tblArtikelen where 
  ArtikelCode = 7 AND 
    (ArtikelIsVoorraad in (1,0) 
    OR ArtikelIsVoorraad in ('1','0') 
    OR ArtikelIsVoorraad in (TRUE,FALSE)
    );

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.