← Back to MySQL Course | Chapter 3: Data Types | Lesson 6 of 8

BOOLEAN Data Type

BOOLEAN in MySQL is like a light switch that is really stored as a small number, with 0 meaning off and 1 meaning on.
Syntax
sql
column_name BOOLEAN

Introduction to BOOLEAN

MySQL has no dedicated BOOLEAN storage type; declaring a column BOOLEAN is simply shorthand that MySQL silently converts to TINYINT(1) under the hood, storing TRUE as 1 and FALSE as 0.

Example: Introduction to BOOLEAN

sql
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE);

True and False Values

You can insert or compare using either the literal keywords TRUE/FALSE or the raw integers 1/0 — MySQL treats them as fully interchangeable, so there's no functional difference between the two styles.

Example: True and False Values

sql
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE);
INSERT INTO users VALUES (1);

Boolean in WHERE Clauses

Because the column is really just a small integer, you can reference it directly in a WHERE clause (e.g. WHERE is_active) without writing an explicit = TRUE comparison — MySQL treats any nonzero value as truthy.

Example: Boolean in WHERE Clauses

sql
CREATE TABLE users (is_active BOOLEAN);
INSERT INTO users VALUES (TRUE), (FALSE);
SELECT * FROM users WHERE is_active;

Boolean Expressions

SUM() on a boolean-style column is a common trick for counting how many rows are true, since MySQL happily adds 1s and 0s together — a quick way to get a completion count without a separate COUNT(*) filter.

Example: Boolean Expressions

sql
CREATE TABLE tasks (is_done BOOLEAN);
INSERT INTO tasks VALUES (TRUE), (TRUE), (FALSE);
SELECT SUM(is_done) AS completed_count FROM tasks;

Boolean Default Values

Giving a boolean column a DEFAULT value (commonly 0/false) ensures every new row starts in a known, predictable state rather than relying on the application to always remember to set it explicitly.

Example: Boolean Default Values

sql
CREATE TABLE users (id INT, is_active BOOLEAN DEFAULT 0);
INSERT INTO users (id) VALUES (1);
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Expecting BOOLEAN to be a real type, when it is stored as TINYINT(1) and can hold values like 5.
  2. Inserting true as a string instead of TRUE or 1, which is a wrong value or gets converted to 0.
  3. Comparing with = NULL instead of IS NULL when the boolean can be missing.
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.