Let us first create a table −
mysql> create table DemoTable -> ( -> EmployeeStatus ENUM('FULLTIME','Intern') default NULL -> ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('FULLTIME'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Intern'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Intern'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+----------------+ | EmployeeStatus | +----------------+ | FULLTIME | | Intern | | Intern | | NULL | +----------------+ 4 rows in set (0.00 sec)
Here is the query to select rows using the ENUM field in MySQL −
mysql> select * from DemoTable -> where EmployeeStatus is null or EmployeeStatus <> 'Intern';
This will produce the following output−
+----------------+ | EmployeeStatus | +----------------+ | FULLTIME | | NULL | +----------------+ 2 rows in set (0.00 sec)