MySQL ENUM column match for quoted values

MySQLMySQLi Database

Let us first create a table with ENUM type column −

mysql> create table DemoTable(
   isMarried ENUM('1','0')
);
Query OK, 0 rows affected (0.46 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('0');
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values('1');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('1');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('0');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('0');
Query OK, 1 row affected (1.00 sec)
mysql> insert into DemoTable values('1');
Query OK, 1 row affected (0.07 sec)
mysql> insert into DemoTable values('0');
Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+
| isMarried |
+-----------+
| 0         |
| 1         |
| 1         |
| 0         |
| 0         |
| 1         |
| 0         |
+-----------+
7 rows in set (0.00 sec)

Following is the query wherein we are counting the quoted value i.e. records with ‘0’ insertion −

mysql> select count(*) from DemoTable where isMarried='0';

This will produce the following output −

+----------+
| count(*) |
+----------+
| 4        |
+----------+
1 row in set (0.06 sec)
raja
Published on 27-Sep-2019 11:02:23
Advertisements