In MySQL, BOOL and BOOLEAN are synonyms for TINYINT(1). FALSE is an alias for 0 and TRUE is an alias for 1; in Boolean expressions, any nonzero non-NULL numeric value evaluates as true.
SELECT 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN;
Output:
| 1 IS TRUE | 0 IS FALSE | NULL is UNKNOWN |
|---|---|---|
| 1 | 1 | 1 |
For two-state application flags, storing only 0 and 1 keeps the meaning clear. However, TINYINT(1) does not restrict storage to those two values. The sample data below deliberately includes 2, 4, and NULL to show the difference.
SELECT * FROM plus2_boolean WHERE feb = TRUE;SELECT * FROM plus2_boolean WHERE feb = 1;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Ronn | 0 | 1 | 0 |
| Lone | 1 | 1 | 4 |
| Raju | NULL | 1 | 0 |
SELECT * FROM plus2_boolean WHERE feb = FALSE;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Alex | 1 | 0 | 1 |
| John | 1 | 0 | 2 |
Full sample table:
| name | jan | feb | mar |
|---|---|---|---|
| Alex | 1 | 0 | 1 |
| Ronn | 0 | 1 | 0 |
| John | 1 | 0 | 2 |
| Lone | 1 | 1 | 4 |
| Raju | NULL | 1 | 0 |
| King | NULL | NULL | 1 |
TRUE is an alias for 1, so mar = TRUE matches only rows that store 1. A Boolean test such as mar IS TRUE accepts any nonzero, non-NULL value. The mar column in our sample includes 1, 2 and 4.
SELECT name, mar
FROM plus2_boolean
WHERE mar = TRUE
ORDER BY name;
Output for exact equality:
| name | mar |
|---|---|
| Alex | 1 |
| King | 1 |
SELECT name, mar
FROM plus2_boolean
WHERE mar IS TRUE
ORDER BY name;
Output for a Boolean test:
| name | mar |
|---|---|
| Alex | 1 |
| John | 2 |
| King | 1 |
| Lone | 4 |
IS FALSE matches zero, while IS UNKNOWN matches NULL. IS NOT TRUE can match both zero and NULL; they are different from IS FALSE.
SELECT * FROM plus2_boolean WHERE mar IS TRUE;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Alex | 1 | 0 | 1 |
| John | 1 | 0 | 2 |
| Lone | 1 | 1 | 4 |
| King | NULL | NULL | 1 |
SELECT * FROM plus2_boolean WHERE jan IS NOT TRUE;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Ronn | 0 | 1 | 0 |
| Raju | NULL | 1 | 0 |
| King | NULL | NULL | 1 |
SELECT * FROM plus2_boolean WHERE jan IS UNKNOWN;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Raju | NULL | 1 | 0 |
| King | NULL | NULL | 1 |
IS TRUE / IS FALSE / IS UNKNOWN is useful when NULL needs to be distinguished from false.
SELECT * FROM plus2_boolean WHERE jan = feb;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Lone | 1 | 1 | 4 |
With ordinary =, comparisons involving NULL evaluate to NULL.
SELECT * FROM plus2_boolean WHERE jan <=> feb;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Lone | 1 | 1 | 4 |
| King | NULL | NULL | 1 |
The NULL-safe equality operator <=> returns 1 when both operands are NULL and 0 or 1 for other comparisons.
SELECT name,
IF(jan, 'OK', 'NOT OK') AS jan,
IF(feb, 'OK', 'NOT OK') AS feb,
IF(mar, 'OK', 'NOT OK') AS mar
FROM plus2_boolean;
Output:
| name | jan | feb | mar |
|---|---|---|---|
| Alex | OK | NOT OK | OK |
| Ronn | NOT OK | OK | NOT OK |
| John | OK | NOT OK | OK |
| Lone | OK | OK | OK |
| Raju | NOT OK | OK | NOT OK |
| King | NOT OK | NOT OK | OK |
In IF(jan, 'OK', 'NOT OK'), MySQL treats 0 and NULL as not true, so both display NOT OK. If NULL must be shown separately, test it first with IS NULL or use a CASE expression.
MySQL Boolean-style values can be displayed as HTML checkboxes. A nonzero value produces a checked checkbox, while 0 or NULL produces an unchecked checkbox in this IF() example.
SELECT name,
IF(jan, '<input type="checkbox" checked>', '<input type="checkbox">') AS jan,
IF(feb, '<input type="checkbox" checked>', '<input type="checkbox">') AS feb,
IF(mar, '<input type="checkbox" checked>', '<input type="checkbox">') AS mar
FROM plus2_boolean;
The following checkboxes show the initial values stored in the sample table. You can check or uncheck them to see how checkboxes behave.
| name | jan | feb | mar |
|---|---|---|---|
| Alex | |||
| Ronn | |||
| John | |||
| Lone | |||
| Raju | |||
| King |
These checkboxes are a visual demonstration. Changing their status here does not update the MySQL database. NULL values are also displayed as unchecked because of the IF() logic.
Learn how jQuery sends checkbox changes to PHP and updates the corresponding database record without reloading the page.
Try the jQuery Data Matrix Example →UPDATE plus2_boolean SET mar = TRUE WHERE name = 'Ronn';UPDATE plus2_boolean SET mar = 0 WHERE name = 'Ronn';UPDATE plus2_boolean SET mar = NOT mar WHERE name = 'Ronn';
In the toggle example above, NOT mar becomes 0 for any nonzero value, 1 for zero, and remains NULL for NULL. Use it for known 0/1 flags rather than to preserve arbitrary numeric values. Run these UPDATE examples on a copy of the sample data.
INSERT INTO plus2_boolean (name, jan, feb, mar) VALUES
('Alex', 1, 0, 1), ('Ronn', 0, 1, 0);INSERT INTO plus2_boolean (name, jan, feb, mar) VALUES
('Alex2', TRUE, FALSE, TRUE), ('Ronn2', FALSE, TRUE, FALSE);
See the related checkbox data-matrix tutorial
The INSERT examples add new records; running them more than once can create duplicates or conflicts depending on the table definition. Test INSERT and UPDATE statements on a practice copy.
Declaring a column BOOLEAN alone does not prevent values such as 2. For a new two-state flag, a NOT NULL column and CHECK constraint make that requirement explicit:
CREATE TABLE boolean_flags_demo (
id INT PRIMARY KEY,
is_active BOOLEAN NOT NULL DEFAULT FALSE,
CONSTRAINT chk_active_binary CHECK (is_active IN (0, 1))
);
MySQL 8.0.16 and later enforce CHECK constraints. This is a separate example table; the plus2_boolean sample intentionally allows values 2, 4 and NULL for comparison demonstrations.
Related operations: comparison operators, UPDATE, and INSERT.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.