Display TRUE FALSE records as 0 1 in MySQL

MySQLMySQLi Database

Set the column as BOOLEAN to display 0 and 1 values. Let us create a table −

mysql> create table DemoTable2035
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> isMarried boolean,
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.72 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable2035(Name,isMarried) values('Chris',true);
Query OK, 1 row affected (0.10 sec)

mysql> insert into DemoTable2035(Name,isMarried) values('David',false);
Query OK, 1 row affected (0.08 sec)

mysql> insert into DemoTable2035(Name,isMarried) values('Bob',true);
Query OK, 1 row affected (0.11 sec)

mysql> insert into DemoTable2035(Name,isMarried) values('Mike',false);
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable2035;

This will produce the following output −

+----+-------+-----------+
| Id | Name  | isMarried |
+----+-------+-----------+
| 1  | Chris | 1         |
| 2  | David | 0         |
| 3  | Bob   | 1         |
| 4  | Mike  | 0         |
+----+-------+-----------+
4 rows in set (0.00 sec)
raja
Published on 07-Apr-2020 15:05:39
Advertisements