BOOLEAN in mysql code example

Example 1: mysql bool

-- In Mysql, BOOL and BOOLEAN are both aliases for TINYINT.
-- zero is considered false.
-- any non-zero value is considered true.

Example 2: mysql is in list

SELECT 
    column1,column2,...
FROM
    table_name
WHERE 
	(expr|column_1) IN ('value1','value2',...);

Example 3: mysql in

SELECT 
    column1,column2,...
FROM
    table_name
WHERE 
    column1 IN ('value1','value2',...);

Example 4: boolean mysql

-- MySQL doesn't have a boolean. Instead, use TINYINT. BOOL and BOOLEAN
-- are aliases to TINYINT. 0 is true, while 1 is false for TINYINT.
-- You can also use TRUE, FALSE, true, false, True, or false as
-- aliases for 0 and 1 respectively.

CREATE TABLE IF NOT EXISTS boolTest (
  thisFieldIsTrue TINYINT DEFAULT 0 -- True by default
  thisFieldIsFalse TINYINT DEFAULT 1 -- False by default
  thisIsAlsoTru BOOL DEFAULT True -- True by default, see above for alternates to True and Bool
 )

Example 5: boolean mysql

SELECT true, false, TRUE, FALSE, True, False;
-- 1 0 1 0 1 0

Tags:

Sql Example