IS operator

IS operator checks data against Boolean values. Boolean data can take values TRUE or FALSE or UNKNOWN.
SELECT 1 IS  TRUE, 0 IS FALSE , NULL IS UNKNOWN
Output
1 IS TRUE0 IS FALSENULL is UNKNOWN
111

Reading data from tinyint field

You can download the plus2_boolean table from here.
SELECT * FROM `plus2_boolean` WHERE mar IS TRUE
If data is equal to 1 or more than it will return TRUE.
namejanfebmar
Alex101
John102
Lone114
KingNULLNULL1

Using IS NOT TRUE

SELECT * FROM `plus2_boolean` WHERE jan  IS NOT TRUE
This includes NULL data also.
namejanfebmar
Ronn010
RajuNULL10
KingNULLNULL1
Boolean operator IS can be used to check UNKNOWN values. This will return True for Null values.
SELECT * FROM `plus2_boolean` WHERE jan  IS UNKNOWN
namejanfebmar
RajuNULL10
KingNULLNULL1
Watch the difference between IS NOT TRUE and IS UNKNOWN, both are not same.
More on NULL Value & Null safe operator

Tutorial on how checkbox is used to update Boolean data in MySQL table.

Using IS operator in varchar columns

We have string data in our student3 table ( download the sql dump ).
SELECT * from student3 where class IS TRUE
Output
idnameclassmark
7My John Rob55
Any value 1 or more will return True while comparing with IS operator. Here for record no 7 we have 5 in class column, so it returns True.
SELECT * from student3 WHERE class IS FALSE
We will get all records except the records where class value is 1 or more ( one record , id = 7 ) , where NULL value is present. ( three records id 2,4 ,6 )
SELECT * from student3 WHERE class IS UNKNOWN
Output
idnameclassmark
2Max RuinNULL85
4Krish StarNULLNULL
6Alex JohnNULL55
SQL dump of student3 table
Comparison Operators SQL CASE SQL sum in multiple columns


plus2net.com






Post your comments , suggestion , error , requirements etc here
















We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer